mercredi 4 février 2015

PIC16f84 dice with 3 buttons

I'm trying to make a LED dice with PIC16f84 using assembly language. There are 3 buttons. 1st button: simple throw 1-6 2nd button: 1-6, but double chance to number 4 3rd button: only 2 or 4 or 6 are possible


I've started to write but I'm in trouble with the parts like (pseudo)random number generator. So I copy-paste the code and hope Somebody can add those parts. I really appreciate your help! P.S.: Sorry for my bad english, it's not my native language.


;** Declaration ** PROCESSOR 16f84


include "p16f84.inc"


__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC ;** Constants ** LEDOne EQU B'00000001' ; Dice side 1 LEDTwo EQU B'00000100' ; 2 LEDThree EQU B'00000101' ; 3 LEDFour EQU B'00000110' ; 4 LEDFive EQU B'00000111' ; 5 LEDSix EQU B'00001110' ; 6 A_Dice EQU PORTB PCL EQU 02 count EQU 0C Taster1 EQU 0 Taster2 EQU 1 Taster3 EQU 2


;** Variables ** Cblock 0x0c WCYCLE ; wait makro variable PRESCwait endc


;** hardware **


ORG 0x00 goto Main ORG 0x04 goto Main


;** program memory **


Main bsf STATUS,RP0 ;BANK1 movlw b'00011111' ;PORTA 0-4 input movwf TRISA movlw b'00000000' ;PORTB all output movwf TRISB bcf STATUS,RP0 ;BANK0



clrf A_Dice ;


; Main loop reload movlw 06 ; counter reset movwf count ; 6 start btfsc PORTA,Taster1 ; PORTA.0 button test goto tast2 ; If it isn't pressed chaeck tast 2 goto compare1 ; pressed tast2 btfsc PORTA,Taster2 ; PORTA.1 button test goto tast3 ; If it isn't pressed chaeck tast 3 goto compare2 ; Taster2 pressed, results from table tast3 btfsc PORTA,Taster3 ; PORTA.2 button test goto nexnum ; if it isn't pressed go to nexnum goto compare3 ; Taster3 is pressed, results from table


compare1 call Data_Table1 ; call table(1-6) goto disp ; display result compare2 call Data_Table2 ; call table(2,4,6) goto disp ; display result compare3 call Data_Table3 ; call table(1,2,3,4,4,5,6) disp movwf A_Dice ; send result to LEDs goto start


nexnum decfsz count ; decrement counter and check if 0? goto start goto reload ; counter reset


Data_Table1 movf count,w addwf PCL nop retlw LEDOne retlw LEDTwo retlw LEDThree retlw LEDFour retlw LEDFive retlw LEDSix


Data_Table2 movf count,w addwf PCL nop retlw LEDTwo retlw LEDTwo retlw LEDFour retlw LEDFour retlw LEDSix retlw LEDSix


Data_Table3 movf count,w addwf PCL retlw LEDOne retlw LEDTwo retlw LEDThree retlw LEDFour retlw LEDFour retlw LEDFive retlw LEDSix End





Aucun commentaire:

Enregistrer un commentaire