I've taken the sample code given to me by crystalfontz and have tried to convert it to code for the atmega8 microcontroller, but I don't get anything on the screen.
It's hooked up properly, a -3.5 V is on Vo, and +5V on Vdd. All we get is a full screen of turned on pixels. Also able to vary the voltage on Vo to adjust the contrast.
Here's the code, if anybody could point out what's wrong I would greatly appreciate it (for the defined constants, those are defined for what we've chose for our chip):
It's hooked up properly, a -3.5 V is on Vo, and +5V on Vdd. All we get is a full screen of turned on pixels. Also able to vary the voltage on Vo to adjust the contrast.
Here's the code, if anybody could point out what's wrong I would greatly appreciate it (for the defined constants, those are defined for what we've chose for our chip):
Code:
//===============================================
// Senior Design - AirControl
// 10/28/2004
// LCD Initialization Test
//===============================================
#include <avr/io.h>
#include <avr/delay.h>
#include <stdlib.h>
//Constants
#define Set_RW (temp_init |= 0x02)
#define Clr_RW (temp_init &= ~0x02)
#define Set_DI (temp_init |= 0x01)
#define Clr_DI (temp_init &= ~0x01)
#define Set_E (temp_init |= 0x04)
#define Clr_E (temp_init &= ~0x04)
#define Set_CS1 (temp_init &= ~0x08) // note: Active Low! switched logic
#define Clr_CS1 (temp_init |= 0x08)
#define Set_CS2 (temp_init &= ~0x10) // note: Active Low! switched logic
#define Clr_CS2 (temp_init |= 0x10)
#define Set_RS (temp_init &= ~0x20) // note: Active Low! switched logic
#define Clr_RS (temp_init |= 0x20)
#define data_out(x) (PORTD = x)
#define reg_out (PORTB = temp_init)
typedef short unsigned int ubyte;
void lines(void);
void Wait(int);
int main (void)
{
while(1)
{
lines();
}
return 1;
}
void Wait(int us)
{
if(us == 10)
{
for(int i=0; i<1000; i++)
{
asm ("nop");
}
// _delay_loop_1(27);
}
else if(us == 1)
{
// _delay_loop_1(3);
for(int i=0; i<100; i++)
{
asm ("nop");
}
}
}
void lines(void)
{
DDRD = 0xFF;
DDRB = 0XFF;
ubyte temp_init = 0x00;
//Idle E
Clr_E;
reg_out;
// Talk to control register
Clr_RS;
reg_out;
// Talk to both controllers
Clr_CS1;
reg_out;
Wait(10);
Clr_CS2;
reg_out;
// Display On
PORTD = 0x3F;
Wait(1);
Set_E;
reg_out;
Clr_E;
reg_out;
Wait(10);
// Display Start Line: AAAAA : RW/DI/DB7:DB0 "0/0/11AAAAAA"
PORTD = 0xC0;
Wait(1);
Set_E;
reg_out;
Clr_E;
reg_out;
Wait(10);
int row;
for(row=0;row<=7;row++)
{
//Set X address
PORTD = 0xB8|row;
Wait(1);
Set_E;
reg_out;
Clr_E;
reg_out;
Wait(1);
//Set Y address 0
PORTD = 0x40;
Wait(1);
Set_E;
reg_out;
Clr_E;
reg_out;
Wait(1);
//Aim at the data register.
Set_RS;
reg_out;
//Talk to controller 1 only
Set_CS1;
reg_out;
int
col;
for(col=0;col<=63;col++)
{
//FDATA(cfag12864b[row][col]);
PORTD = 0x88;
Set_E;
reg_out;
Wait(1);
Clr_E;
reg_out;
Wait(1);
}
//Talk to the controller 2
Clr_CS1;
reg_out;
Set_CS2;
reg_out;
for(col=64;col<=127;col++)
{
//FDATA(cfag12864b[row][col]);
PORTD = 0x88;
Set_E;
reg_out;
Wait(1);
Clr_E;
reg_out;
Wait(1);
}
//Talk to both controllers
Clr_CS1;
reg_out;
Clr_CS2;
reg_out;
//Aim back to the control register.
Clr_RS;
reg_out;
}
}
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.