#include<util/delay.h>
#include<avr/io.h>
#include"defines.h"
void control_write(unsigned char control)
{
GLCD_DATA_DDR = 0XFF;
GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_E);
GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RW);
GLCD_CTRL_PORT |= (1<<GLCD_CTRL_CS0);
GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RS);
asm volatile ("nop"); asm volatile ("nop");
asm volatile ("nop"); asm volatile ("nop");
GLCD_CTRL_PORT |= (1<<GLCD_CTRL_E);
asm volatile ("nop"); asm volatile ("nop");
GLCD_DATA_PORT = 0x3e;
GLCD_CTRL_PORT |= (1<<GLCD_CTRL_RW);
asm volatile ("nop"); asm volatile ("nop");
}
unsigned char control_read()
{
unsigned char control;
GLCD_DATA_DDR = 0X00;
GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_E);
GLCD_CTRL_PORT |= (1<<GLCD_CTRL_RW);
GLCD_CTRL_PORT |= (1<<GLCD_CTRL_CS0);
GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RS);
asm volatile ("nop"); asm volatile ("nop");
asm volatile ("nop"); asm volatile ("nop");
GLCD_CTRL_PORT |= (1<<GLCD_CTRL_E);
asm volatile ("nop"); asm volatile ("nop");
control = GLCD_DATA_PIN;
GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RW);
asm volatile ("nop"); asm volatile ("nop");
return control;
}
int main(void){
unsigned char control;
_delay_ms(100);
DDRB = 0xFF;
GLCD_CTRL_DDR = 0XFF;
GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RESET);
while(1){
//CONTROL WRITE
control_write(GLCD_ON_CTRL);
//CONTROL READ
control = control_read();
PORTB |= (1<<1);
if(control & GLCD_STATUS_BUSY)
PORTB |= (1<<0);
}
return 0;
}