Anda di halaman 1dari 5

LIST p = 16F887 ed #INCLUDE <P16F887.

INC>

;Simply sets the processor type being us ;file for processor, adds predifined labels

__CONFIG _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _LV P_OFF ; Sets many parameters org 0x00 ; Start the code at location zero LCD_PORT Equ PORTB LCD_TRIS Equ TRISB LCD_RS Equ 0x04 ;LCD handshake lines LCD_E Equ 0x05 CBLOCK 0x20 count ; Counter used when switch pressed has stopped count1 ; 160us Counter variable counta ; variables for delay timers countb ; variables for delay timers LCDTemp ; 4 bit for LCD ENDC ; org 0x000 ; goto Init ; HEX_Table addwf PCL, f retlw 0x30 retlw 0x31 retlw 0x32 retlw 0x33 retlw 0x34 retlw 0x35 retlw 0x36 retlw 0x37 retlw 0x38 retlw 0x39 retlw 0x41 retlw 0x42 retlw 0x43 retlw 0x44 retlw 0x45 retlw 0x46 Text addwf retlw retlw retlw retlw retlw retlw retlw retlw retlw retlw retlw PCL, f 'W' 'A' 'M' 'B' 'U' 'L' 'U' 'L' 'U' ' ' ' '

retlw ' ' retlw 0x00 Text2 addwf retlw retlw retlw retlw retlw retlw retlw retlw retlw PCL, f 'B' 'D' 'N' 'S' 'O' 'N' ' ' ' ' ' '

retlw 0x00 ; Initialize the PIC and the LCD Init ; bsf STATUS,5 bsf STATUS,6 clrf ANSEL clrf ANSELH bcf bcf bcf bcf bsf movlw movwf d 7 clrf clrf clrf bcf STATUS,5 CM1CON0,7 CM2CON1,7 STATUS,6 STATUS,5 0XC0 TRISA TRISB TRISC TRISD STATUS,5

;set memory bank 3 ;cofigure pins as digital ;set memory bank 2 ;disable comparators ;set memory bank 1 ;set port A as output except output 6 an ;set ;set ;set ;set port B port C port D memory as output as output as output bank 0

call LCDInit ; Initialize the LCD Display ; Main program... Message movf count, w ; put counter value in W goto NextMessage ; display next message if finished xorlw 0x00 ; is it a zero? btfsc STATUS, Z call text; get a character from the text table call LCD_Char incf count, f goto Message NextMessage call LCD_L2 ;move to 2nd row, first column clrf count ;set counter register to zero Message2

movf count, w ;put counter value in W call Text2 ;get a character from the text table xorlw 0x00 ;is it a zero? btfsc STATUS, Z goto EndMessage call LCD_Char incf count, f goto Message2 EndMessage ; Infinate loop Stop goto Stop ;endless loop ; LCD routines and subs LCDInit ; 4 Bit Initialization... call Del05 ; Wait 15 msecs call Del05 ; call Del05 ; movlw 0x03 ; Send the Reset Instruction movwf LCD_PORT ; call Pulse_e ; Pulse LCD_E call Del05 ; Delay 5ms call Pulse_e ; Pulse LCD_E call D160us ; Delay of 160us call Pulse_e ; Pulse LCD_E call D160us ; Delay of 160us movlw 0x02 ; Send the Data Length Specification movwf LCD_PORT ; call Pulse_e ; Pulse LCD_E call D160us ; Delay of 160us movlw 0x028 ; Set Interface Length call LCDIns ; movlw 0x010 ; Turn Off Display call LCDIns ; movlw 0x001 ; Clear Display RAM call LCDIns ; movlw 0x006 ; Set Cursor Movement call LCDIns ; movlw 0x00C ; Turn on Display/Cursor call LCDIns ; call LCD_Clr ; Clear the LCD return ; LCDIns ; Send the Instruction to the LCD movwf LCDTemp ; Save the Value swapf LCDTemp, 1 movf LCDTemp, 0 andlw 0x0F ; Most Significant Nibble first movwf LCD_PORT ; bcf LCD_PORT, LCD_RS ; call Pulse_e ; swapf LCDTemp, w ; Least Significant Nibble Second andlw 0x0F ; movwf LCD_PORT ; bcf LCD_PORT, LCD_RS ; call Pulse_e ; call Del01 ; wait 1 ms movf LCDTemp, w ;

andlw 0xFC ; Have to Delay 5 msecs? btfsc STATUS, Z ; call Del01 ; 1ms return ; LCD_CharD addlw 0x30 ; add 0x30 to convert to ASCII LCD_Char ; Send the Character to the LCD movwf LCDTemp ; Save the Value swapf LCDTemp, 1 MovF LCDTemp, 0 andlw 0x0F ; Most Significant Nibble first movwf LCD_PORT ; bsf LCD_PORT, LCD_RS ; call Pulse_e ; swapf LCDTemp, w ; Least Significant Nibble Second andlw 0x0F ; movwf LCD_PORT ; bsf LCD_PORT, LCD_RS ; call Pulse_e ; call Del05 ; nop ; return ; LCD_L2: movlw 0xc0 ; move to 2nd row, first column call LCDIns ; retlw 0x00 ; LCD_Clr movlw 0x01 ; Clear display call LCDIns ; retlw 0x00 ; Pulse_e ; bsf LCD_PORT, LCD_E ; LCD Enable pulse to write data from PORTB nop ; into LCD module. nop bcf LCD_PORT, LCD_E ; nop ; nop retlw 0x00 ; ; Delay routines... D160us clrf count1 ; bsf count1, 5 ; Delay 160 usecs bsf count1, 4 ; decfsz count1, f ; goto $ - 1 ; return ; Del255 movlw 0xff ; delay 255 mS goto d0 ; Del200 movlw d'255' ; delay 200mS goto d0 ; Del100 movlw d'200' ; delay 100mS goto d0 ; Del50 movlw d'100' ; delay 50mS goto d0 ;

Del20 movlw d'40' ; delay 20mS goto d0 ; Del05 movlw 0x10 ; delay 5.000 ms (4 MHz clock) goto d0 ; Del01 movlw 0x05 ; delay 1.000 ms (4 MHz clock) d0 movwf count1 ; d1 movlw 0xC7 ; delay 1mS movwf counta ; movlw 0x04 ; movwf countb ; Del_0 decfsz counta,f ; goto $+2 ; decfsz countb,f ; goto Del_0 ; decfsz count1,f ; goto d1 ; retlw 0x00 ; end

Anda mungkin juga menyukai