/********************************************************** * Test program for LCD Siemens C55 * ATmega168, q=32768, RC=8MHz * For IAR AVR Compiler **********************************************************/ #include "iom168.h" #include //=== Hardware depended defines === #define LCD_RST_DDR DDRD_Bit4 #define LCD_RST_PORT PORTD_Bit4 #define LCD_RST_PIN PIND_Bit4 #define LCD_CE_DDR DDRD_Bit5 #define LCD_CE_PORT PORTD_Bit5 #define LCD_CE_PIN PIND_Bit5 #define LCD_DC_DDR DDRD_Bit6 #define LCD_DC_PORT PORTD_Bit6 #define LCD_DC_PIN PIND_Bit6 #define LCD_VDD_DDR DDRD_Bit7 #define LCD_VDD_PORT PORTD_Bit7 #define LCD_VDD_PIN PIND_Bit7 #define LCD_MOSI_DDR DDRB_Bit3 #define LCD_MOSI_PORT PORTB_Bit3 #define LCD_MOSI_PIN PINB_Bit3 #define LCD_SCK_DDR DDRB_Bit5 #define LCD_SCK_PORT PORTB_Bit5 #define LCD_SCK_PIN PINB_Bit5 #define LCD_SS_DDR DDRB_Bit2 #define LCD_SS_PORT PORTB_Bit2 #define LCD_SS_PIN PINB_Bit2 //=== LCD function prototypes === void LSend ( unsigned char, char ); void LOn(void); void LReset (void); void LInitSiemensC55(void); void LInitNokia3310(void); void LInitPCF8812(void); void LTestOut(void); void SInit(void); void Delay(unsigned int); void Delay2(unsigned int); //========================================================= int main(void) { PORTB=0; // All port to out "0" (check your device for no conflict) DDRB=0xFF; PORTC=0; DDRC=0xFF; PORTD=0; DDRD=0xFF; SInit(); LInitSiemensC55(); // LInitNokia3310(); // LInitPCF8812(); LTestOut(); while(1); // Stop program } //========================================================= //=== Test Output to LCD === void LTestOut(void) { unsigned int i; for ( i=0; i<(51); i++ ) { LSend(0x01, 1); LSend(0x01, 1); LSend(0x02, 1); LSend(0x02, 1); LSend(0x04, 1); LSend(0x04, 1); LSend(0x08, 1); LSend(0x08, 1); LSend(0x10, 1); LSend(0x10, 1); LSend(0x20, 1); LSend(0x20, 1); LSend(0x40, 1); LSend(0x40, 1); LSend(0x80, 1); LSend(0x80, 1); }; } //=== Send byte to LCD === // cd: 1 - data, 0 - command void LSend ( unsigned char data, char cd ) { Delay(1); if ( cd == 1 ) { LCD_DC_PORT = 1; } else { LCD_DC_PORT = 0; }; Delay(1); LCD_CE_PORT = 0; Delay(1); SPDR = data; // Send data to display controller. while (!(SPSR&(1<0; i--) { __watchdog_reset(); __no_operation(); }; } //=== Delay === void Delay2(unsigned int delay) //delay ~ in mS for CPUclk=8MHz { unsigned int i; for (i=delay; i>0; i--) { Delay(1000); }; }