|
|
View previous topic :: View next topic |
Author |
Message |
matrix2k
Joined: 16 Mar 2004 Posts: 2
|
LCD and PIC16f876A |
Posted: Tue Mar 16, 2004 11:19 am |
|
|
Hi, we are stuck at this problem we are trying to print some text on the lcd
type KS0066U
the lcd driver doesn't work so we wrote our own, we are using 8bit communication.
the lcd starts up but it writes some of the message wrongly, every second letter is correct.
please need some help fast, we are getting mad on this peace of #%"#&%"#&
Code: |
#include <16F876A.h>
#fuses HS, NOWDT, NOBROWNOUT, NOPUT,NOPROTECT
#use delay (clock=20000000)
#byte tris_a=0x85
#byte tris_b=0x86
#byte port_a=0x05
#byte port_b=0x06
#define forever while(2<3);
#define ascii port_b
void writetxt(char* text);
main()
{
int i=0;
char strang[20];
set_tris_b(0x00); /* 1 => input, 0 => output */
set_tris_a(0x00); /* alla output */
delay_ms(2000);
OUTPUT_HIGH(PIN_A0); // RS=1
OUTPUT_HIGH(PIN_A1); // R/W=1
OUTPUT_LOW(PIN_A2); // E=0
delay_ms(1);
OUTPUT_LOW(PIN_A0); // RS=0
OUTPUT_LOW(PIN_A1); // R/W=0
delay_us(1);
OUTPUT_HIGH(PIN_A2); // E=1
delay_us(1);
ascii = 0x3F;
OUTPUT_LOW(PIN_A2); // E=0
delay_us(139);
delay_us(1);
OUTPUT_HIGH(PIN_A0); // RS=1
OUTPUT_HIGH(PIN_A1); // R/W=1
delay_us(1);
OUTPUT_LOW(PIN_A0);
OUTPUT_LOW(PIN_A1);
delay_us(1);
OUTPUT_HIGH(PIN_A2);
delay_us(1);
ascii = 0x0F;
OUTPUT_LOW(PIN_A2); // E=0
delay_us(139);
delay_us(1);
OUTPUT_HIGH(PIN_A0); // RS=1
OUTPUT_HIGH(PIN_A1); // R/W=1
delay_us(1);
OUTPUT_LOW(PIN_A0);
OUTPUT_LOW(PIN_A1);
delay_us(1);
OUTPUT_HIGH(PIN_A2);
delay_us(1);
ascii = 0x01;
OUTPUT_LOW(PIN_A2); // E=0
delay_us(139);
delay_us(1);
OUTPUT_HIGH(PIN_A0); // RS=1
OUTPUT_HIGH(PIN_A1); // R/W=1
delay_us(1);
OUTPUT_LOW(PIN_A0);
OUTPUT_LOW(PIN_A1);
delay_us(1);
OUTPUT_HIGH(PIN_A2);
delay_us(1);
ascii = 0x07;
OUTPUT_LOW(PIN_A2); // E=0
delay_ms(15);
delay_us(1);
OUTPUT_HIGH(PIN_A0); // RS=1
OUTPUT_HIGH(PIN_A1); // R/W=1
delay_us(1);
delay_ms(1);
strcpy(strang, "Hello World");
writetxt(strang);
}
void writetxt(char* text)
{
int i = 0;
while(text[i] != 0)
{
OUTPUT_HIGH(PIN_A0);
OUTPUT_LOW(PIN_A1);
delay_us(1);
OUTPUT_HIGH(PIN_A2);
OUTPUT_LOW(PIN_A1); // R/W=1
delay_us(1);
ascii = text[i++];
OUTPUT_LOW(PIN_A2); // E=0
delay_ms(200);
delay_us(1);
OUTPUT_LOW(PIN_A0); // RS=0
OUTPUT_HIGH(PIN_A1); // R/W=1
OUTPUT_HIGH(PIN_A1); // R/W=1
delay_us(1);
delay_ms(200);
}
}
|
_________________ ~The MATRIX~ |
|
|
Guest
|
|
Posted: Tue Mar 16, 2004 7:55 pm |
|
|
i was getting errors when i started. but i manged to fix it using a very technical method, i turned the lcd on its itside!!!
i guess i must have had a loose connection, but i checke dit a few times. maybe your connection is loose. |
|
|
matrix2k
Joined: 16 Mar 2004 Posts: 2
|
|
Posted: Wed Mar 17, 2004 1:56 pm |
|
|
thanx will check that,,, i would apriciate if someone could test this code on their own lcd, so that we know if code works....
PIC: PIC16f876A
LCD: KS0066U
PORT B is data
port A0 is RS
port A1 is RW
port A2 is E
thanks again _________________ ~The MATRIX~ |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|