Further to above, I have now gone back to trying to operate the LCD in 8 bit mode using SPI to transfer the data into a hc595 shift register. I am using 2 general purpose ports for enable and reset bits to the LCD, R/W pin is grounded.
The data seems to shifts into the S/R ok but only appears at the output parallel pins if I connect the storage and shift clocks together. Pulsing the master reset has no effect. I cannot get the LCD to even initialize. I have attached the code if anybody can see where I am going wrong I would be eternally greatful.
Martin
Message Edited by marti on 04-06-200608:56 AM
#define CMD 0 // For command mode RST-low, EN-high
#define DISP 1 // For display mode RST-high, EN-high
#define EN 0x08
#define RS 0x04
#define MR 0x10
/*--- Port direction and SPI setup ---*/
void SPI_Set(void){
DDRM = 0x38; // Set PortM as output
DDRT = 0x1C; // Set PortT as output
SPICR1 = 0x50; // Set SPI control register 1
SPICR2 = 0x0; // Set SPI control register 2
SPIBR = 0x0; //Set max baud rate
PTT |= MR; //Master reset for hc595 set high
}
/*--- Delay Code ---*/
/*--- Needs to be configured to Bus clock, Boot 24Mhz, Run 4Mhz ---*/
void Delay(unsigned int sec, unsigned int mult){
unsigned int i, j;
for(i = 0; i < sec; i++){
for(j = 0; j < mult; j++){
}
}
}
/*-- Routine to send command or character to display --*/
void set_lcd(char n, char reg){
unsigned char dummy;
//First send the byte to the HC595
if(reg == DISP){ // Command or write?
PTT |= EN|RS; // Command EN and RS high
}else{
PTT |= EN; // Write EN only high
}
SPIDR = n; // Send byte into shift register
while((SPISR & 0x80) == 0); // Wait for SPI ready SPIF interrupt flag
PTT &= ~MR; PTT |= MR; /*Pulse MR to load 595 storage register
This doesn't seem to have any effect. Data only latches when shift and storage clocks are connected together*/
dummy = SPIDR; //Clear ready bit
PTT &= ~(EN|RS); // Tell LCD to do it
Delay(3, 100); //100uS delay for LCD operation
}
/*---- Main program ---*/
void main(void){
EnableInterrupts;
SPI_Set(); // Initialize SPI system and serial ports
Delay(40,1000); //Wait 15mS after power on
set_lcd(0x30, CMD); //Function set 8 bits
Delay(10,1000);//wait 4.1mS
set_lcd(0x30, CMD); //Function set 8 bits
set_lcd(0x30, CMD); //Function set 8 bits
set_lcd(0x38, CMD); //Set 8 bit 2 lines
set_lcd(0xE, CMD); //Display on, Cursor on
set_lcd(0x6, CMD); //Set Cursor
for(;
{
set_lcd(0x57, DISP); //display "W"
set_lcd(0x45, DISP); //display "e"
}
}
Message Edited by marti on 04-06-200608:59 AM