/***************************************************** This program was produced by the CodeWizardAVR V2.03.4 Standard Automatic Program Generator © Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Version : Date : 17.12.2009 Author : Company : Comments: Chip type : AT90USB162 Program type : Application Clock frequency : 16,000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 128 *****************************************************/ #include <90usb162.h> \\#include "font5x7.c" #include #include #define LCD_DATA_LINE PORTC.7 #define LCD_CLOCK_LINE PORTB.7 #define LCD_D_C_LINE PORTC.6 #define LCD_SCE_LINE PORTC.5 #define LCD_RES_LINE PORTC.4 #define LCD_DATA_LINE_ON DDRC.7 #define LCD_CLOCK_LINE_ON DDRB.7 #define LCD_D_C_LINE_ON DDRC.6 #define LCD_SCE_LINE_ON DDRC.5 #define LCD_RES_LINE_ON DDRC.4 #define LCD_X_RES 84 //разрешение экрана #define LCD_Y_RES 48 #define LCD_CACHE_SIZE LCD_X_RES*LCD_Y_RES/8 char ctr; unsigned char LcdCache [LCD_CACHE_SIZE]; //Cache buffer in SRAM 84*48 bits or 504 bytes unsigned int LcdCacheIdx; //Cache index void led_blk(void) { PORTC.2 = 1; delay_ms(50); PORTC.2 = 0; delay_ms(50); }; void data_for_lcd(char data_to_lcd) { ctr = 8; while(ctr) { LCD_DATA_LINE = data_to_lcd & 0b10000000; data_to_lcd <<= 1; ctr --; LCD_CLOCK_LINE = 1; LCD_CLOCK_LINE = 0; }; }; void writecomm(char data_to_lcd) { LCD_D_C_LINE = 0; LCD_SCE_LINE = 0; data_for_lcd(data_to_lcd); LCD_SCE_LINE = 1; }; void writedata(char data_to_lcd) { LCD_D_C_LINE = 1; LCD_SCE_LINE = 0; data_for_lcd(data_to_lcd); LCD_SCE_LINE = 1; }; void cursorxy(char x, char y) { writecomm(0x40|(y&0x07)); // Y axis writecomm(0x80|(x&0x7f)); // X axis } ; void clearram(void) { int ddram; cursorxy(0,0); // Cursor Home. for (ddram=864;ddram>0;ddram--) {writedata(0x00);} // 6*84 = 504 DDRAM addresses. }; void lcd_init(void) { LCD_RES_LINE = 1; LCD_SCE_LINE = 1; LCD_RES_LINE =0; delay_ms(100); LCD_RES_LINE = 1; writecomm(0x21); writecomm(0xC8); writecomm(0x13); writecomm(0x20); writecomm(0x09); clearram(); writecomm(0x08); writecomm(0x0C); cursorxy(0,0); }; void LcdChr (int ch) //Displays a character at current cursor location and increment cursor location { unsigned char i; for ( i = 0; i < 5; i++ ) LcdCache[LcdCacheIdx++] = table[(ch*5+i)]; //выбеляем байт-столбик из символа и грузим в массив - 5 раз LcdCache[LcdCacheIdx++] = 0x00; //добавляем пробел между символами }; // Declare your global variables here void main(void) { // Declare your local variables here // Crystal Oscillator division factor: 1 #pragma optsize- CLKPR=0x80; CLKPR=0x00; #ifdef _OPTIMIZE_SIZE_ #pragma optsize+ #endif // Input/Output Ports initialization // Port B initialization // Func7=Out Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=0 State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTB=0x00; DDRB=0x80; // Port C initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In // State7=0 State6=0 State5=0 State4=0 State3=T State2=T State1=T State0=T PORTC=0x00; DDRC=0xF4; // Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0x00; DDRD=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0A output: Disconnected // OC0B output: Disconnected TCCR0A=0x00; TCCR0B=0x00; TCNT0=0x00; OCR0A=0x00; OCR0B=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer 1 Stopped // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // OC1C output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off // Compare C Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; OCR1CH=0x00; OCR1CL=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: Off // INT2: Off // INT3: Off // INT4: Off // INT5: Off // INT6: Off // INT7: Off EICRA=0x00; EICRB=0x00; EIMSK=0x00; // PCINT0 interrupt: Off // PCINT1 interrupt: Off // PCINT2 interrupt: Off // PCINT3 interrupt: Off // PCINT4 interrupt: Off // PCINT5 interrupt: Off // PCINT6 interrupt: Off // PCINT7 interrupt: Off PCMSK0=0x00; // PCINT8 interrupt: Off // PCINT9 interrupt: Off // PCINT10 interrupt: Off // PCINT11 interrupt: Off // PCINT12 interrupt: Off PCMSK1=0x00; PCICR=0x00; // Timer/Counter 0 Interrupt(s) initialization TIMSK0=0x00; // Timer/Counter 1 Interrupt(s) initialization TIMSK1=0x00; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; lcd_init(); led_blk(); \\cursorxy(1, 1); \\writedata(0x01); cursorxy(2, 4); writedata(0x46); writedata(0x49); writedata(0x49); writedata(0x49); writedata(0x31); writedata(0x00); writedata(0x00); writedata(0x00); writedata(0x00); writedata(0x00); writedata(0x7F); writedata(0x09); writedata(0x19); writedata(0x29); writedata(0x46); }