Voorbeeld Source Code ;------------------------------------------------------------ ;Configuration Word page 21 list p=16f84A;f=inhx8m ; 16F84A Runs at 4 MHz (1us=1 instruction cycles) _CP_OFF equ H'3FFF' ; CP (bit 13-4) code protection bit disabled _PWRTE_ON equ H'3FFF' ; PWRTE not (bit 3) => "0" power up timer is enabled _WDT_OFF equ H'3FFB' ; WDTE (bit 2) => "0" WDT watchdog timer disabled _XT_OSC equ H'3FFD' ; FOSC1 : FOSC0 (bit 1-0) => "0" : "1" xt oscillator __CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC ;------------------------------------------------------------ ;CPU Intialisation page 6 porta equ 05 ; File register adres "00000101" 05d portb equ 06 ; File register adres "00000110" 06d count1 equ 0C ; File register adres "00001100" 12d general purpose count2 equ 0D ; File register adres "00001101" 13d general purpose count3 equ 0E ; File register adres "00001110" 14d general purpose afisaj equ 0F ; File register adres "00001111" 15d general purpose #DEFINE sclk portb,6 ; Rb6 is serial clock line #DEFINE sdta portb,7 ; Rb7 is input serial data line #DEFINE dorc porta,0 ; Ra0 is select register (H = Data, L =Command) #DEFINE rset porta,1 ; Ra1 is reset (L = Enable) #DEFINE tens porta,2 ; Ra2 is Vcmd LCD power supply on / off #DEFINE enab porta,3 ; Ra3 is Chip select (L = Enable) ;------------------------------------------------------------ ;Set the current program start location org 0 ;------------------------------------------------------------ ;Initialize the ports init movlw 0x00 ; move 0 into W register tris portb ; set portB to be all outputs movwf portb ; all ouput low movlw 0x00 ; move 0 into W register tris porta ; set portA to be all outputs movwf porta ; all ouput low start call pause ; not necessary can be deleted bsf dorc ; bytes are stored in the display data ram, address counter ; incremented automatically bsf enab ; chip disabled bsf tens ; turn on Vcmd LCD power supply ??????why now and not earlier ( time for microcontroller reset R1-C3 it is Vuc dependent and some display cannot work because the typical response to reset time what is cca. 20-30 ms) call lcres ; lcd needs a 250 ms reset time after Vdd it is high movlw 21H ;set extins extended instruction set movwf afisaj ; lcd accumulator afisaj=21h (it is better to change the syntax from 21H to 0x21 because syntax with xxH are reserved by Mpasm compiler only until 81H call lccmd ; command subroutine movlw .197 ;Vop the syntax C5H will not work because it is higher as 80H, but the syntax 0xC5 it is OK so just change it! movwf afisaj call lccmd movlw 13H ;bias movwf afisaj call lccmd movlw 20H ;afisare orizontala horizontal mode from left to right, X axe are incremented automatically , 0x22 for vertical addressing ,back on normal instruction set too movwf afisaj call lccmd movlw 09H ;mod control all on just a test if lcd panel are without missing dots , change to syntax 0x09 movwf afisaj call cbild ;resetare DDRAM after reset the Ddram value are randomise according with the lcd controller data sheet (it real, believe me)so a lcd clearing it is necessary call lccmd ; because the afisaj value it is not affected during the cbild subroutine, can be used in this mode but it better to move this command before call cbild call pause movlw 08H ;mod control blank change to syntax 0x08 movwf afisaj call lccmd call pause movlw 0CH ;mod control normal change to syntax 0x0C movwf afisaj call lccmd movlw 40H ;x ini X axe initialisation, change to syntax 0x40 movwf afisaj call lccmd movlw 80H ;y ini y axe initialisation, change to syntax 0x80 movwf afisaj call lccmd adata movlw 1FH ;date change to syntax 0x1F movwf afisaj call lcdta movlw 05H ;date movwf afisaj call lcdta movlw 07H ;date movwf afisaj call lcdta goto adata lcdta bsf dorc ; bytes are stored in the display data ram, address counter ; incremented automatically bcf enab ; chip enabled call varsa bsf enab ; chip disabled retlw 00 lccmd bcf dorc ; byte is a command it is read with the eight SCLK pulse bcf enab ; chip enabled call varsa bsf enab ; chip disabled retlw 00 lcres bcf rset ; reset enabled call pause bsf rset ; reset disabled retlw 00 varsa bcf sclk ; negative edge (varsa= ausnehmen ) this subroutine send the value of afisaj , bit by bit in serial mode btfsc afisaj,7 ;bit0(MSB) if bit 7 of afisaj = 1 then sdta=1 bsf sdta ; serial data line is high btfss afisaj,7 ; if bit 7 of afisaj = 0 then sdta=0 bcf sdta ; serial data line is low call halta ; can be replaced with a nop if a higher speed it is needed bsf sclk ; positive edge call halta ; can be replaced with a nop if a higher speed it is needed bcf sclk ; negative edge btfsc afisaj,6 ;bit1 if bit 6 of afisaj = 1 then sdta=1 bsf sdta ; serial data line is high btfss afisaj,6; if bit 6 of afisaj = 0 then sdta=0 bcf sdta ; serial data line is low call halta bsf sclk ; positive edge call halta bcf sclk ; negative edge btfsc afisaj,5 ;bit2 bsf sdta ; serial data line is high btfss afisaj,5 bcf sdta ; serial data line is low call halta bsf sclk ; positive edge call halta bcf sclk ; negative edge btfsc afisaj,4 ;bit3 bsf sdta ; serial data line is high btfss afisaj,4 bcf sdta ; serial data line is low call halta bsf sclk ; positive edge call halta bcf sclk ; negative edge btfsc afisaj,3 ;bit4 bsf sdta ; serial data line is high btfss afisaj,3 bcf sdta ; serial data line is low call halta bsf sclk ; positive edge call halta bcf sclk ; negative edge btfsc afisaj,2 ;bit5 bsf sdta ; serial data line is high btfss afisaj,2 bcf sdta ; serial data line is low call halta bsf sclk ; positive edge call halta bcf sclk ; negative edge btfsc afisaj,1 ;bit6 bsf sdta ; serial data line is high btfss afisaj,1 bcf sdta ; serial data line is low call halta bsf sclk ; positive edge call halta bcf sclk ; negative edge btfsc afisaj,0 ;bit7(LSB) bsf sdta ; serial data line is high btfss afisaj,0 bcf sdta ; serial data line is low call halta bsf sclk ; positive edge call halta bcf sclk ; negative edge retlw 00 cbild bcf sdta ; serial data line is low a null value it is send to ddram movlw .6 ; set the maximal value for Y axe movwf count3 c3 movlw .84 ; set the maximal value for X axe movwf count1 c1 movlw .8 ; for a serial transmission of one byte , a number of 8 clock cycles are need movwf count2 bsf dorc ; null value bytes are stored in the display data ram, address counter ; incremented automatically bcf enab ; chip enabled c2 bcf sclk ; negative edge ;at this stage sdta=0 and lcd begin to be cleared nop ; no operation nop ; no operation bsf sclk ; positive edge decfsz count2 goto c2 bsf enab ; chip disabled decfsz count1 goto c1 decfsz count3 goto c3 retlw 00 ; can be replaced with a return , it is not necessary to clear W pause movlw .7 ; move 7d into W register to be replace syntax with 0x07, execution time 7* 37.5=262.5 ms movwf count3 ; move 7d into count3 variabele d3 movlw .50 ; to be replace syntax with 0x32 ,execution time 50*.75= 37.5 ms (37.44) movwf count1 d1 movlw .250 ; to be replace syntax with 0xFA execution time 250*3=750 us (749) movwf count2 d2 decfsz count2 goto d2 decfsz count1 goto d1 decfsz count3 goto d3 retlw 00 halta movlw 20H ; move "0010 0000" 32d into W register this subroutine it is use to see the events with a low speed 32*64*3=6144 us, decfsz need 2us and goto need 1 us movwf count1 ; move "0010 0000" 32d into count1 variabele g1 movlw 40H ; move "0100 0000" 64d into W register movwf count2 ; move "0010 0000" 64d into count2 variabele g2 decfsz count2 ; decrement count2 goto g2 ; until count2 is 0 decfsz count1 ; decrement count1 goto g1 ; until count1 is 0 retlw 00 ;------------------------------------------------------------ end ;======================