You should connect 8 Data lines and 3 control lines(used as output Port) to interface the LCD(assuming it is an Alphanumeric Character type LCD). So I am using Port C as data lines and Port E as control lines.
I have attached a sample code in MPLAB sim. Probably should work with mikroBasic or mikroC also.
Code Basic4GL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 main: ADCON1 = 7 ' All pins digital. CMCON = 7 ' All comparator Off. TRISB = %11111111 ' PINS RB0-RB7 Configured as Inputs. TRISC = %00000000 ' PORTC Configured as Output. TRISD = %00000000 ' PORTD Configured as Outputs. PORTB = 0 ' PORTB initialized to zero. PORTC = 0 ' PORTC initialized to zero. PORTD = 0 ' PORTD initialized to zero. Lcd_Config(PORTC,6,5,4,3,PORTC,0,1,2) Lcd_Cmd(LCD_CURSOR_OFF) while(1) if(PORTB = %00000001) then delay_ms(10) if(PORTB = %00000001) then PORTD = %00000001 Lcd_Cmd(LCD_CLEAR) Lcd_Out(1,1, "LED ON") end if end if if(PORTB = %00000010) then delay_ms(10) if(PORTB = %00000010) then PORTD = %00000000 Lcd_Cmd(LCD_CLEAR) Lcd_Out(1,1, "LED OFF") end if end if
You should connect 8 Data lines and 3 control lines(used as output Port) to interface the LCD(assuming it is an Alphanumeric Character type LCD). So I am using Port C as data lines and Port E as control lines.
I have attached a sample code in MPLAB sim. Probably should work with mikroBasic or mikroC also.
[syntax = basic]
main:
ADCON1 = 7 ' All pins digital.
CMCON = 7 ' All comparator Off.
TRISB = %11111111
TRISC = %00000000
TRISD = %00000000
PORTB = 0
PORTC = 0
PORTD = 0
Lcd8_Config(PORTE, PORTC, 0,1,2, 7,6,5,4,3,2,1,0)
Lcd8_Cmd(LCD_CURSOR_OFF)
Lcd8_Cmd(LCD_CLEAR)
while(1)
if (PORTB = %00000001) then
delay_ms(10)
if (PORTB = %00000001) then
PORTD = %00000001
Lcd8_Cmd(LCD_CLEAR)
Lcd8_Out(1,1, "LED ON")
Lcd8_Out(2,1, "LED ON")
Lcd8_Out(3,1, "LED ON")
Lcd8_Out(4,1, "LED ON")
end if
end if
if (PORTB = %00000010) then
delay_ms(10)
if (PORTB = %00000010) then
PORTD = %00000000
Lcd8_Cmd(LCD_CLEAR)
Lcd8_Out(1,1, "LED OFF")
Lcd8_Out(2,1, "LED OFF")
Lcd8_Out(3,1, "LED OFF")
Lcd8_Out(4,1, "LED OFF")
end if
end if
wend
end.
[/syntax]
You should check your Initialization code of your display. Or may be the address you are sending for 2nd and 4th line may be wrong. Try different address and check for the correct one.
At what voltage are you operating your controller? What is the current consumption of your LED?
It looks like the code is fine. Give the above details. Try using the reverse logic to glow the LED. Connect the +ve terminal of LED to +Vcc and connect the -ve terminal to D.0 through a current limiting resistor. Send 1 to turn off LED and 0 to turn on.
I have attached a sample code of the LCD interface with 4 data lines. It uses PORTD and PORTE for interface. Change the IO to your requirement.
For other two lines, try using the following as the starting address of the lines. You should first send the address of the location you want to display.
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0.
Any two of the above should work for the other two lines.
Where did you get Lcd8_Cmd() and Lcd8_Out() ? ..... Can you give the original code?
I have never worked in mikroBasic or mikroC. I have only worked in MPLAB Sim. So I cant help it.
Where did you get Lcd8_Cmd() and Lcd8_Out() ? From the code that you have attached, I believe the first parameter decides the Line of the Display. Can you give the original code?
Actually you should send the address before you send any data to LCD. Then you should send the ASCII Value of the data to be displayed. It will be in the below way:
If you want display "ABCDEF" from the 5th Position of the first line, your code should be (from the sample code that I have previously attached):
lcdcmd (0x84); // Send the Address
for (i=0x41; i<0x47; i++)
lcddat (i); // Send the ASCII Value of the data to be displayed
If only 2nd and 4th lines are not displaying, there are only two possibilities. One is that you are sending wrong address. Other is that the display itself is faulty. Debug your code properly with the above data. You should be able solve the problem.
I have never worked in mikroBasic or mikroC. I have only worked in MPLAB Sim. So I cant help it.
Where did you get Lcd8_Cmd() and Lcd8_Out() ? From the code that you have attached, I believe the first parameter decides the Line of the Display. Can you give the original code?
Actually you should send the address before you send any data to LCD. Then you should send the ASCII Value of the data to be displayed. It will be in the below way:
If you want display "ABCDEF" from the 5th Position of the first line, your code should be (from the sample code that I have previously attached):
lcdcmd (0x84); // Send the Address
for (i=0x41; i<0x47; i++)
lcddat (i); // Send the ASCII Value of the data to be displayed
If only 2nd and 4th lines are not displaying, there are only two possibilities. One is that you are sending wrong address. Other is that the display itself is faulty. Debug your code properly with the above data. You should be able solve the problem.
[SYNTAX = MIKROBASIC]
'Microcontroller: PIC16F877A
'Clock Frequency: 8Mhz
main:
ADCON1 = 7 ' All pins digital.
CMCON = 7 ' All comparator Off.
TRISB = %00011111
TRISC = %00000000
TRISD = %00000000
TRISE = %000
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0
Lcd8_Config(PORTE, PORTC, 0,1,2, 7,6,5,4,3,2,1,0)
Lcd8_Cmd(LCD_CURSOR_OFF)
Lcd8_Cmd(LCD_CLEAR)
Lcd8_Out(1,1, "LCD TEST")
Lcd8_Out(2,1, "LCD TEST")
Lcd8_Out(3,1, "LCD TEST")
Lcd8_Out(4,1, "LCD TEST")
while(1)
select case PORTB
case %00000001
delay_ms(10)
if (PORTB = %00000001) and (PORTD.0 = 0) then
PORTD.0 = 1
Lcd8_Cmd(LCD_CLEAR)
Lcd8_Out(1,1, "RELAY ON")
Lcd8_Out(2,1, "RELAY ON")
Lcd8_Out(3,1, "RELAY ON")
Lcd8_Out(4,1, "RELAY ON")
end if
case %00000010
delay_ms(10)
if (PORTB = %00000010) and (PORTD.0 = 1) then
PORTD.0 = 0
Lcd8_Cmd(LCD_CLEAR)
Lcd8_Out(1,1, "RELAY OFF")
Lcd8_Out(2,1, "RELAY OFF")
Lcd8_Out(3,1, "RELAY OFF")
Lcd8_Out(3,1, "RELAY OFF")
end if
end select
wend
end.
[/SYNTAX]
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?