SUPER-EZEE
Newbie level 1
pic16f84a lcd
Greetings guys. I am currently working on a project using the PIC where I am programming a PIC and interfacing it with a 16x2 HD44100H LCD, programming in assembler. I have used one of the bits on PORT A as an input bit. Each time the input bit is low it triggers the PIC to display a message on the LCD. There's a counter which counts how many times the RA3 pin is low and each trigger displays a different message.
there's only 4 messages, and each time the trigger count reaches 4, it resets to zero.
The PROBLEM: After programming, when I switch on the PIC the 4 messages just print one after the other without the trigger pin being pressed. Secondly, I have refined the code but it doesn't wanna work. I need help.
I have attached the code and any suggestions are welcome.
=====================================================
//Title: Design Project 3 Train Program
//Author: Nikkie & Enoch
//Rev. & Date: 23 March 2009
#define LCD_E PORTA,RA0 //LCD Enable control line
#define LCD_RW PORTA,RA1 //LCD Read/Write control line
#define LCD_RS PORTA,RA2 //LCD Register-Select control line
#define BUSYFLAG PORTB,7 //LCD 'Busy' flag output
#define INPUTBIT PORTA,RA3 //Input line
COUNTER EQU 0C
CNT1 EQU 0D //Counter variables used in the execution of the delay
CNT2 EQU 0E
CNT3 EQU 0F
LCD_TEMP EQU 10
//**************************************************************
INIT: BSF STATUS,RP0 //Memory Bank 1
MOVLW 0x00 //Setting port B and as output
MOVWF TRISB //Output to LCD Data lines
MOVLW 0x08 //Bit 3 of Port A an input bit and 0-2 output to LCD RS,RW,E
MOVWF TRISA
BCF STATUS,RP0 //Switching to memory bank 0
CLRF PORTB //Clearing the output port
CLRF PORTA //Clearing the Input Port
NOP //Clearing all the variables
CLRF COUNTER
CLRF LCD_TEMP
CLRF CNT1
CLRF CNT2
CLRF CNT3
CALL LCD_INIT //Initialising the LCD display
CALL LCDCLR
//**************************************************************
START: CALL CHECK
MOVF COUNTER,w //Checking if the input code is of station 1
XORLW 0x01
BTFSC STATUS,Z
CALL DISPST1
MOVF COUNTER,w
XORLW 0x02 //Checking if the input code is of station 2
BTFSC STATUS,Z
CALL DISPST2
MOVF COUNTER,w //Checking if the input code is of station 3
XORLW 0x03
BTFSC STATUS,Z
CALL DISPST3
MOVF COUNTER,w //Checking if the input code is of station 4
XORLW 0x04
BTFSC STATUS,Z
CALL DISPST4
GOTO START
//**************************************************************
//LCD displaying functions
DISPST4: CALL WAIT
MOVLW 0x50 //Displaying 'P'
CALL WR_DATA
CALL WAIT
MOVLW 0x61 //Displaying 'A'
CALL WR_DATA
CALL WAIT
MOVLW 0x72 //Displaying 'R'
CALL WR_DATA
CALL WAIT
MOVLW 0x6F //Displaying 'O'
CALL WR_DATA
CALL WAIT
MOVLW 0x77 //Displaying 'W'
CALL WR_DATA
CALL DEL2S
CALL LCDCLR
CALL DEL20MS
RETURN
//**************************************************************
DISPST3: CALL WAIT
MOVLW 0x45 //Displaying 'E'
CALL WR_DATA
CALL WAIT
MOVLW 0x7C //Displaying 'L'
CALL WR_DATA
CALL WAIT
MOVLW 0x73 //Displaying 'S'
CALL WR_DATA
CALL WAIT
MOVLW 0x69 //Displaying 'I'
CALL WR_DATA
CALL WAIT
MOVLW 0x65 //Displaying 'E'
CALL WR_DATA
CALL WAIT
MOVLW 0x73 //Displaying 'S'
CALL WR_DATA
CALL DEL2S
CALL LCDCLR
CALL DEL20MS
RETURN
//**************************************************************
DISPST2: CALL WAIT
MOVLW 0x56 //Displaying 'V'
CALL WR_DATA
CALL WAIT
MOVLW 0x61 //Displaying 'A'
CALL WR_DATA
CALL WAIT
MOVLW 0x73 //Displaying 'S'
CALL WR_DATA
CALL WAIT
MOVLW 0x63 //Displaying'C'
CALL WR_DATA
CALL WAIT
MOVLW 0x6F //Displaying'O'
CALL WR_DATA
CALL DEL2S
CALL LCDCLR
CALL DEL20MS
RETURN
//**************************************************************
DISPST1: CALL WAIT
MOVLW 0x4D //Displaying'M'
CALL WR_DATA
CALL WAIT
MOVLW 0x75 //Displaying'U'
CALL WR_DATA
CALL WAIT
MOVLW 0x74 //Displaying'T'
CALL WR_DATA
CALL WAIT
MOVLW 0x75 //Displaying'U'
CALL WR_DATA
CALL WAIT
MOVLW 0x61 //Displaying'A'
CALL WR_DATA
CALL WAIT
MOVLW 0x7C //Displaying'L'
CALL WR_DATA
CALL DEL2S
CALL LCDCLR
CALL DEL20MS
RETURN
//**************************************************************
//A function which sets the LCD to be ready for accepting data
WR_DATA: MOVWF LCD_TEMP //Character to be sent is in W
CALL WAIT //Wait for LCD to be ready
BCF LCD_RW //Set LCD in read mode
BSF LCD_RS //Set LCD in data mode
BSF LCD_E //LCD Enable line HIGH
MOVF LCD_TEMP,w
MOVWF PORTB //Send data to LCD
BCF LCD_E //LCD Enable line LOW
RETURN
//**************************************************************
CHECK: BTFSC INPUTBIT //Monitoring if the input button is pressed
GOTO CHECK
CALL DEL20MS
BTFSC INPUTBIT
GOTO CHECK
INCF COUNTER,f //Increment the station counter variable
MOVLW 0x00
MOVF COUNTER,w //Moving the value of COUNTER variable
XORLW 0x05 //Checking if the value of COUNTER is equal to 5
BTFSC STATUS,Z //Z flag will be zero if the value of COUNTER is 5
CALL DOWN //Reduce the value of COUNTER
RETURN
DOWN: CLRF COUNTER //Restart counting stations from 1
RETURN
//**************************************************************
//20 milli-seconds delay
DEL20MS: MOVLW 0x1A
MOVWF CNT2
LOOP1: MOVLW 0xFF
MOVWF CNT1
LOOP2: DECFSZ CNT1,f
GOTO LOOP2
DECFSZ CNT2,f
GOTO LOOP1
RETURN
//**************************************************************
//LCD Initialising function
LCD_INIT: CALL DEL20MS
MOVLW 0x38
MOVWF PORTB
BCF LCD_RS
BCF LCD_RW
BSF LCD_E
BCF LCD_E
CALL DEL20MS
CALL WAIT
MOVLW 0x0F
MOVWF PORTB
BCF LCD_RS
BCF LCD_RW
BSF LCD_E
BCF LCD_E
CALL DEL20MS
CALL WAIT
MOVLW 0x01
MOVWF PORTB
BCF LCD_RS
BCF LCD_RW
BSF LCD_E
BCF LCD_E
CALL DEL20MS
CALL WAIT
MOVLW 0x06
BCF LCD_RS
BCF LCD_RW
BSF LCD_E
BCF LCD_E
CALL DEL20MS
CALL WAIT
RETURN
//**************************************************************
//A function for monitoring if the LCD busy flag is set
WAIT: BTFSC BUSYFLAG
GOTO WAIT
CALL DEL20MS
BTFSC BUSYFLAG
GOTO WAIT
RETURN
//**************************************************************
//2 SECOND DELAY
DEL2S: MOVLW 0x0A
MOVWF CNT3
PART1: MOVLW 0xFF
MOVWF CNT2
PART1A: MOVLW 0xFF
MOVWF CNT1
PART1B: DECFSZ CNT1,f
GOTO PART1B
NOP
PART2: DECFSZ CNT2,f
GOTO PART1A
DECFSZ CNT3,f
GOTO PART1
RETURN
//**************************************************************
//A function to clear the display
LCDCLR: MOVLW 0x01
CALL WR_DATA
RETURN
//**************************************************************
ORG 0x2007 // Configuration Word
DW 0x3FF1
END
Greetings guys. I am currently working on a project using the PIC where I am programming a PIC and interfacing it with a 16x2 HD44100H LCD, programming in assembler. I have used one of the bits on PORT A as an input bit. Each time the input bit is low it triggers the PIC to display a message on the LCD. There's a counter which counts how many times the RA3 pin is low and each trigger displays a different message.
there's only 4 messages, and each time the trigger count reaches 4, it resets to zero.
The PROBLEM: After programming, when I switch on the PIC the 4 messages just print one after the other without the trigger pin being pressed. Secondly, I have refined the code but it doesn't wanna work. I need help.
I have attached the code and any suggestions are welcome.
=====================================================
//Title: Design Project 3 Train Program
//Author: Nikkie & Enoch
//Rev. & Date: 23 March 2009
#define LCD_E PORTA,RA0 //LCD Enable control line
#define LCD_RW PORTA,RA1 //LCD Read/Write control line
#define LCD_RS PORTA,RA2 //LCD Register-Select control line
#define BUSYFLAG PORTB,7 //LCD 'Busy' flag output
#define INPUTBIT PORTA,RA3 //Input line
COUNTER EQU 0C
CNT1 EQU 0D //Counter variables used in the execution of the delay
CNT2 EQU 0E
CNT3 EQU 0F
LCD_TEMP EQU 10
//**************************************************************
INIT: BSF STATUS,RP0 //Memory Bank 1
MOVLW 0x00 //Setting port B and as output
MOVWF TRISB //Output to LCD Data lines
MOVLW 0x08 //Bit 3 of Port A an input bit and 0-2 output to LCD RS,RW,E
MOVWF TRISA
BCF STATUS,RP0 //Switching to memory bank 0
CLRF PORTB //Clearing the output port
CLRF PORTA //Clearing the Input Port
NOP //Clearing all the variables
CLRF COUNTER
CLRF LCD_TEMP
CLRF CNT1
CLRF CNT2
CLRF CNT3
CALL LCD_INIT //Initialising the LCD display
CALL LCDCLR
//**************************************************************
START: CALL CHECK
MOVF COUNTER,w //Checking if the input code is of station 1
XORLW 0x01
BTFSC STATUS,Z
CALL DISPST1
MOVF COUNTER,w
XORLW 0x02 //Checking if the input code is of station 2
BTFSC STATUS,Z
CALL DISPST2
MOVF COUNTER,w //Checking if the input code is of station 3
XORLW 0x03
BTFSC STATUS,Z
CALL DISPST3
MOVF COUNTER,w //Checking if the input code is of station 4
XORLW 0x04
BTFSC STATUS,Z
CALL DISPST4
GOTO START
//**************************************************************
//LCD displaying functions
DISPST4: CALL WAIT
MOVLW 0x50 //Displaying 'P'
CALL WR_DATA
CALL WAIT
MOVLW 0x61 //Displaying 'A'
CALL WR_DATA
CALL WAIT
MOVLW 0x72 //Displaying 'R'
CALL WR_DATA
CALL WAIT
MOVLW 0x6F //Displaying 'O'
CALL WR_DATA
CALL WAIT
MOVLW 0x77 //Displaying 'W'
CALL WR_DATA
CALL DEL2S
CALL LCDCLR
CALL DEL20MS
RETURN
//**************************************************************
DISPST3: CALL WAIT
MOVLW 0x45 //Displaying 'E'
CALL WR_DATA
CALL WAIT
MOVLW 0x7C //Displaying 'L'
CALL WR_DATA
CALL WAIT
MOVLW 0x73 //Displaying 'S'
CALL WR_DATA
CALL WAIT
MOVLW 0x69 //Displaying 'I'
CALL WR_DATA
CALL WAIT
MOVLW 0x65 //Displaying 'E'
CALL WR_DATA
CALL WAIT
MOVLW 0x73 //Displaying 'S'
CALL WR_DATA
CALL DEL2S
CALL LCDCLR
CALL DEL20MS
RETURN
//**************************************************************
DISPST2: CALL WAIT
MOVLW 0x56 //Displaying 'V'
CALL WR_DATA
CALL WAIT
MOVLW 0x61 //Displaying 'A'
CALL WR_DATA
CALL WAIT
MOVLW 0x73 //Displaying 'S'
CALL WR_DATA
CALL WAIT
MOVLW 0x63 //Displaying'C'
CALL WR_DATA
CALL WAIT
MOVLW 0x6F //Displaying'O'
CALL WR_DATA
CALL DEL2S
CALL LCDCLR
CALL DEL20MS
RETURN
//**************************************************************
DISPST1: CALL WAIT
MOVLW 0x4D //Displaying'M'
CALL WR_DATA
CALL WAIT
MOVLW 0x75 //Displaying'U'
CALL WR_DATA
CALL WAIT
MOVLW 0x74 //Displaying'T'
CALL WR_DATA
CALL WAIT
MOVLW 0x75 //Displaying'U'
CALL WR_DATA
CALL WAIT
MOVLW 0x61 //Displaying'A'
CALL WR_DATA
CALL WAIT
MOVLW 0x7C //Displaying'L'
CALL WR_DATA
CALL DEL2S
CALL LCDCLR
CALL DEL20MS
RETURN
//**************************************************************
//A function which sets the LCD to be ready for accepting data
WR_DATA: MOVWF LCD_TEMP //Character to be sent is in W
CALL WAIT //Wait for LCD to be ready
BCF LCD_RW //Set LCD in read mode
BSF LCD_RS //Set LCD in data mode
BSF LCD_E //LCD Enable line HIGH
MOVF LCD_TEMP,w
MOVWF PORTB //Send data to LCD
BCF LCD_E //LCD Enable line LOW
RETURN
//**************************************************************
CHECK: BTFSC INPUTBIT //Monitoring if the input button is pressed
GOTO CHECK
CALL DEL20MS
BTFSC INPUTBIT
GOTO CHECK
INCF COUNTER,f //Increment the station counter variable
MOVLW 0x00
MOVF COUNTER,w //Moving the value of COUNTER variable
XORLW 0x05 //Checking if the value of COUNTER is equal to 5
BTFSC STATUS,Z //Z flag will be zero if the value of COUNTER is 5
CALL DOWN //Reduce the value of COUNTER
RETURN
DOWN: CLRF COUNTER //Restart counting stations from 1
RETURN
//**************************************************************
//20 milli-seconds delay
DEL20MS: MOVLW 0x1A
MOVWF CNT2
LOOP1: MOVLW 0xFF
MOVWF CNT1
LOOP2: DECFSZ CNT1,f
GOTO LOOP2
DECFSZ CNT2,f
GOTO LOOP1
RETURN
//**************************************************************
//LCD Initialising function
LCD_INIT: CALL DEL20MS
MOVLW 0x38
MOVWF PORTB
BCF LCD_RS
BCF LCD_RW
BSF LCD_E
BCF LCD_E
CALL DEL20MS
CALL WAIT
MOVLW 0x0F
MOVWF PORTB
BCF LCD_RS
BCF LCD_RW
BSF LCD_E
BCF LCD_E
CALL DEL20MS
CALL WAIT
MOVLW 0x01
MOVWF PORTB
BCF LCD_RS
BCF LCD_RW
BSF LCD_E
BCF LCD_E
CALL DEL20MS
CALL WAIT
MOVLW 0x06
BCF LCD_RS
BCF LCD_RW
BSF LCD_E
BCF LCD_E
CALL DEL20MS
CALL WAIT
RETURN
//**************************************************************
//A function for monitoring if the LCD busy flag is set
WAIT: BTFSC BUSYFLAG
GOTO WAIT
CALL DEL20MS
BTFSC BUSYFLAG
GOTO WAIT
RETURN
//**************************************************************
//2 SECOND DELAY
DEL2S: MOVLW 0x0A
MOVWF CNT3
PART1: MOVLW 0xFF
MOVWF CNT2
PART1A: MOVLW 0xFF
MOVWF CNT1
PART1B: DECFSZ CNT1,f
GOTO PART1B
NOP
PART2: DECFSZ CNT2,f
GOTO PART1A
DECFSZ CNT3,f
GOTO PART1
RETURN
//**************************************************************
//A function to clear the display
LCDCLR: MOVLW 0x01
CALL WR_DATA
RETURN
//**************************************************************
ORG 0x2007 // Configuration Word
DW 0x3FF1
END