Newhaven Display Forum
Newhaven Products => Character LCDs => Topic started by: YSUN on November 21, 2014, 02:24:38 PM
-
Hi, All
I have been working on this LCD several days, but get no display on the screen. Firstly, I am pretty sure that all the connections are correct. Here I writing for asking help about the code .
I use the Atmel studio 6.2 , the board is atmega328p mini . PortB0 --PortB7 are for the bus line (8-bit ), PortD pin 0 , 1 , 2 are the control pins.
My code is written based on the example program code given on Newhaven website ( you can find the demo code here : http://www.newhavendisplay.com/app_notes/8_bit_character_C.txt )
And here below is my code :
#include <avr/io.h>
#include <util/delay.h>
#define E PORTB0 // en
#define Rw PORTB1 // R/W
#define Rs PORTB2 // RS
volatile xdata_at_0xB0_char_E;
volatile xdata_at_0xB1_char_Rw;
volatile xdata_at_oxB2_char_Rs;
char const text[] = {"eniware-"};
//void commamd ( char i );
//void write ( char i );
//void init();
//void disp_pic();
//void main(void);
void command (char i)
{
PORTD = i;
PORTB &= ~ (1<<Rs);// rs = 0
PORTB &= ~(1<<Rw);// rw =0
PORTB |= 1<<E;// en = 1
_delay_ms(10);
PORTB &= ~(1<<E); // en = 0
}
void write (char i)
{
PORTD = i;
PORTB |= (1<<Rs); // rs 1
PORTB &= ~ (1<<Rw); // rw 0
PORTB |= 1<<E; // en 1
_delay_ms(10);
PORTB &= ~ (1<<E); // en 0
}
void init()
{
PORTB &= ~ (1<<E); // en 0
_delay_ms(10);
command(0x30); //#1
_delay_ms(100);
command(0x30); //#2
_delay_ms(10);
command(0x30); //#3
_delay_ms(10);
command(0x38);
command(0x10);
command(0x0c);
command(0x06);
}
void disp_pic()
{
int i;
command(0x01);
_delay_ms(10);
for (i=0;i<8;i++)
{
write(text);
}
}
void main (void)
{
PORTD = 0;
PORTB = 0;
while(1)
{
init();
disp_pic();
_delay_ms(1000);
}
}
Is there anyone can tell me what is wrong with my code ? Many thanks in advance.
-
Our example code is verified to work correctly. Have you verified your signals are working/toggling correctly with a scope?
Also, typically you need to set up the ports as outputs in your code.
For example :
DDRB = 0xFF;
DDRD = 0xFF;