Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INCLUDE "P16F877.inc"
- List P=16F877
- ;************************************
- d1 equ 0x20
- d2 equ 0x21
- d3 equ 0x22
- w_temp equ 0x23
- status_temp equ 0x24
- ASCI equ 0x25
- var_a equ 0x26
- var_b equ 0x27
- ganger equ 0x28
- EN equ 0x01
- rad equ 0x29
- counter equ 0x30
- state equ 0x31
- dioder equ 0x32
- d11 equ 0x33
- d21 equ 0x34
- letterCounter equ 0x35
- radByte equ 0x36
- rowNumber equ 0x37
- dioder_temp equ 0x38
- ;************************************
- org 0x00
- clrf STATUS
- movlw 0x00
- movwf 0x0A
- goto init
- ;************************************
- org 0x04
- goto avbrott
- ;************************************
- avbrott movwf w_temp
- swapf STATUS,0
- movwf status_temp
- ;***
- ;hämtar tecken från receive reg
- movf RCREG,0
- movwf ASCI
- ;if lettercounter = 16 byt rad
- movlw 0x10
- subwf letterCounter,0
- btfss STATUS,2
- goto general
- clrf letterCounter ;letterCounter = 0, ändrar rad
- ;om rowNumber = 00, byta till rad 2, om row number = FF clear o rad 1
- movlw 0x00 ;byte till rad 2
- subwf rowNumber,0
- btfss STATUS,2
- goto rowTwoTest
- movlw 0xFF ;sätter RowNumber till FF, rad 2
- movwf rowNumber
- movlw 0xC0
- movwf radByte
- call change_row
- goto done
- rowTwoTest movlw 0xFF ;kollar rad 2
- subwf rowNumber,0
- btfss STATUS,2
- goto done
- clrf letterCounter
- ;incf letterCounter
- call clear_display
- clrf rowNumber
- done
- general ;skicka tecten till LCD
- movfw ASCI
- call Visa_LCD
- ;call waithz
- incf letterCounter
- ;***
- swapf status_temp,0
- movwf STATUS
- swapf w_temp,1
- swapf w_temp,0
- retfie
- ;************************************
- change_row movfw radByte
- movwf rad
- andlw 0xF0
- movwf PORTD
- call enable
- swapf rad,w
- andlw 0xF0
- movwf PORTD
- call enable
- call waitms
- return
- ;************************************
- clear_display movlw 0x01
- movwf rad
- andlw 0xF0
- movwf PORTD
- call enable
- swapf rad,w
- andlw 0xF0
- movwf PORTD
- call enable
- call waitms
- return
- ;************************************
- waitms movlw 0x0a
- movwf var_b
- loop2 movlw 0x64
- movwf var_a
- loop1 decfsz var_a,1
- goto loop1
- decfsz var_b,1
- noll
- goto loop2
- return
- ;************************************
- enable bsf PORTD,EN
- call waitms
- bcf PORTD,EN
- call waitms
- return
- ;************************************
- LCDinit movlw 0xff
- movwf ganger
- loop3 call waitms
- decfsz ganger,1
- goto loop3
- ;Första anrop
- movlw 0x30
- movwf PORTD
- call enable
- ;Vänta mer 4,1ms
- movlw 0x05
- movwf ganger
- loop4 call waitms
- decfsz ganger,1
- goto loop4
- ;andra anrops
- movlw 0x30
- movfw PORTD
- call enable
- ;Vänta mer än 0,1ms
- call waitms
- ;tredje anrop
- movlw 0x30
- movwf PORTD
- call enable
- call waitms
- movlw 0x20
- movwf PORTD
- call enable
- call waitms
- movlw 0x20
- movwf PORTD
- call enable
- movlw 0x80
- movwf PORTD
- call enable
- call waitms
- movlw 0x00 ;clearar displayen
- movwf PORTD
- call enable
- movlw 0x10
- movwf PORTD
- call enable
- call waitms
- movlw 0x00
- movwf PORTD
- call enable
- movlw 0x60
- movwf PORTD
- call enable
- call waitms
- movlw 0x00
- movwf PORTD
- call enable
- movlw 0xE0
- movwf PORTD
- call enable
- call waitms
- return
- Visa_LCD movwf ASCI
- andlw 0xF0
- movwf PORTD
- bsf PORTD,0
- call enable
- swapf ASCI,w
- andlw 0xF0
- movwf PORTD
- bsf PORTD,0
- call enable
- return
- init movlw 0xFF
- movwf PORTA
- movwf PORTB
- clrf PORTC
- clrf PORTD
- bsf STATUS,RP0
- movlw 0x00
- movwf TRISA
- movwf TRISB
- movwf TRISD
- movlw b'11000000' ;tar bort RC7 o RC6 som digitala I/O för UART
- movwf TRISC
- movlw 0x06
- movwf ADCON1
- bcf STATUS,RP0
- ;*** UART INSTÄLLNINGAR ***
- movlw b'10010000'
- movwf RCSTA
- bsf STATUS,RP0
- movlw b'00100110'
- movwf TXSTA
- movlw 0x4D ;77
- movwf SPBRG
- bcf STATUS,RP0
- ; *** AVBROTT INSTÄLLNINGAR ***
- bsf STATUS,RP0
- movlw b'00100000'
- movwf PIE1
- bcf STATUS,RP0
- movlw b'11000000'
- movwf INTCON
- call LCDinit
- movlw 0xFF
- movwf dioder
- bcf dioder,0
- bsf STATUS,0
- clrf counter
- movlw 0xff
- movwf state
- clrf letterCounter
- clrf rowNumber
- goto main
- waithz movlw 0x1A ;2999995 cycles
- movwf d1 ;Delay = 1 second
- movlw 0x8B
- movwf d2
- movlw 0x07
- movwf d3
- Delay_0
- decfsz d1, f
- goto $+2
- decfsz d2, f
- goto $+2
- decfsz d3, f
- goto Delay_0
- ;5 cycles
- goto $+1
- goto $+1
- nop
- return
- shortWait movlw 0x5F
- movwf d11
- movlw 0xEB
- movwf d21
- Delay_1
- decfsz d11, f
- goto $+2
- decfsz d21, f
- goto Delay_1
- ;2 cycles
- goto $+1
- return
- ;dioder '01111111' btfsc dioder,4
- ; '1011111' btfsc dioder,3
- diodFunk btfsc dioder,0 ;bestämmer riktning
- goto fortsatt
- movlw 0x00
- movwf state ;state = 0, vill ha rotation åt vänster
- fortsatt btfsc dioder,7
- goto fortsatt_igen
- movlw 0xff
- movwf state ;state = ff, vill ha rotation åt höger
- fortsatt_igen btfsc state,0
- goto cont1
- RLF dioder,f ;roterar höger
- cont1 btfss state,0 ;rotationslogic
- goto cont2
- RRF dioder,f ;roterar vänster
- cont2 movfw dioder ;flyttar dioder till working
- movwf dioder_temp ;flyttar working till dioder_temp, det är denna som skrivs ut (och används för att inte röra till det i dioder)
- swapf dioder_temp,f ;swappar så att PORTA & PORTB 3210 7654 blir 7654 3210
- movfw dioder_temp
- movwf PORTA ;får dioder att lysa :)
- movwf PORTB
- return
- main
- call shortWait
- call diodFunk
- goto main
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement