#include <avr/io.h>
#include "STRING.H"
#include <stdio.h>
#include <avr/iom128.h>
#include <compat/deprecated.h>
#define F_OSC 16000000 /* oscillator-frequency in Hz */
#define UART_BAUD_RATE 2400
#define UART_BAUD_CALC(UART_BAUD_RATE,F_OSC) ((F_OSC)/((UART_BAUD_RATE)*16l)-1)
#define LCD_A0 PB0
#define LCD_E1 PB1
#define LCD_E2 PB2
#define LCD_RW PB3
#define DATA PORTE
#define LCD_EL PB4
void Delay();
void LCD_On(void);
void LCD_Off(void);
void LCD_Power_Up(void);
void LCD_Power_Down(void);
void LCD_Reset(void);
void LCD_Write_Command(char Command);
void LCD_Write_Data(char LCD_Data);
// -------------------- Delay Loop -----------------------
void Delay(void)
{
int i;
for(i=0; i<100; i++);
}
// -------------------- void LCD_On() -----------------------
void LCD_On(void)
{
LCD_Write_Command(0xAF);
LCD_Write_Command(0xA4); // Static Driving Off
}
// -------------------- void LCD_Off() -----------------------
void LCD_Off(void)
{
cbi(PORTB,LCD_EL);
Delay();
LCD_Write_Command(0xAE); // Static Driving Off
}
// -------------------- void LCD_Power_Up() -----------------------
void LCD_Power_Up(void)
{
//LCD_POWER=0;
cbi(PORTB,LCD_EL);
LCD_Write_Command(0xAE); // Display Off
Delay();
LCD_Write_Command(0xC0); // Start Line Com 0
LCD_Write_Command(0xA4); // Static Driving Off
LCD_Write_Command(0x00); // Column=0 (0-59)
LCD_Write_Command(0xB8); // Page=0 (0-3)
LCD_Write_Command(0xA9); // 1/32 Duty
LCD_Write_Command(0xA9); // adc=CW (Forward)
LCD_Write_Command(0xEE); // end read-modify-write code
LCD_Write_Command(0xAF); // Display ON
}
// -------------------- void LCD_Power_Down() -----------------------
void LCD_Power_Down(void)
{
LCD_Write_Command(0xAE); // Display Off
LCD_Write_Command(0xA5); // Static Driving On
Delay();
cbi(PORTB,LCD_E1);
Delay();
cbi(PORTB,LCD_E2);
Delay();
cbi(PORTB,LCD_RW);
Delay();
cbi(PORTB,LCD_A0);
Delay();
// LCD_POWER=1;
}
// -------------------- void LCD_Reset() -----------------------
void LCD_Reset(void)
{
LCD_Write_Command(0xE2); // Display Off
}
// -------------------- void LCD_Write_Command(char) -----------------------
//
void LCD_Write_Command(char Command)
{
cbi(PORTB,LCD_E1);
Delay();
cbi(PORTB,LCD_E2);
Delay();
cbi(PORTB,LCD_RW);
Delay();
cbi(PORTB,LCD_A0);
Delay();
sbi(PORTB,LCD_E1);
Delay();
sbi(PORTB,LCD_E2);
Delay();
PORTE=Command;
Delay();
cbi(PORTB,LCD_E1);
Delay();
cbi(PORTB,LCD_E2);
Delay();
}
// -------------------- void LCD_Write_Data(char) -----------------------
//
void LCD_Write_Data(char LCD_Data)
{
// if(xaxis==60){LCD_Write_Command(0x00)};
cbi(PORTB,LCD_E1);
Delay();
cbi(PORTB,LCD_E2);
Delay();
cbi(PORTB,LCD_RW);
Delay();
sbi(PORTB,LCD_A0);
Delay();
// if(xaxis<60){sbi(PORTB,LCD_E1);}
// else if(xaxis>59){sbi(PORTB,LCD_E2);}
PORTE=LCD_Data;
Delay();
sbi(PORTB,LCD_E1);
Delay();
sbi(PORTB,LCD_E2);
Delay();
PORTE=LCD_Data;
Delay();
cbi(PORTB,LCD_E1);
Delay();
cbi(PORTB,LCD_E2);
Delay();
}
int main (void)
{
//unsigned char counter;
DDRB = 0xFF;
DDRE = 0xFF;
PORTB = 0x00;
PORTE = 0x00;
LCD_Power_Up();
LCD_Write_Data(0xFF);
LCD_Write_Data(0xFF);
LCD_Write_Data(0xFF);
do
{
}while(1);
}