给你一个完整的12864的程序,已调试通过
#include "iom16.h"
#include "inavr.h"
#define LCD_EN DDRD|=(0X01<<5);PORTD|=(0X01<<5)
#define LCD_DIS DDRD|=(0X01<<5);PORTD&=~(0X01<<5)
#define LCD_R DDRD|=(0X01<<6);PORTD|=(0X01<<6)
#define LCD_W DDRD|=(0X01<<6);PORTD&=~(0X01<<6)
#define LCD_DATA DDRD|=(0X01<<7);PORTD|=(0X01<<7)
#define LCD_COM DDRD|=(0X01<<7);PORTD&=~(0X01<<7)
// 片选1,高有效(前64列)*/
#define LCD_CS1_H DDRD|=(0X01<<4);PORTD|=(0X01<<4)
#define LCD_CS1_L DDRD|=(0X01<<4);PORTD&=~(0X01<<4)
// 片选2,高有效(后64列)
#define LCD_CS2_H DDRD|=(0X01<<3);PORTD|=(0X01<<3)
#define LCD_CS2_L DDRD|=(0X01<<3);PORTD&=~(0X01<<3)
//复位信号,低电平有效
#define LCD_RST_H DDRD|=(0X01<<2);PORTD|=(0X01<<2)
#define LCD_RST_L DDRD|=(0X01<<2);PORTD&=~(0X01<<2)
unsigned int j,f;
__flash unsigned char AscII[96][8]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*" "=00H*/
0x00,0x00,0x00,0x4F,0x00,0x00,0x00,0x00, /*"!"=01H*/
0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00, /*"""=02h*/
0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00, /*"#"=03h*/
0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00, /*"$"=04h*/
0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00, /*"%"=05h*/
0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00, /*"&"=06h*/
0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00, /*"'"=07h*/
0x00,0x00,0x1C,0x22,0x41,0x00,0x00,0x00, /*"("=08h*/
0x00,0x00,0x41,0x22,0x1C,0x00,0x00,0x00, /*")"=09h*/
0x00,0x14,0x08,0x3E,0x08,0x14,0x00,0x00, /*"*"=0Ah*/
0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00, /*"+"=0Bh*/
0x00,0x00,0x50,0x30,0x00,0x00,0x00,0x00, /*";"=0Ch*/
0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00, /*"-"=0Dh*/
0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00, /*"."=0Eh*/
0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00, /*"/"=0Fh*/
0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00, /*"0"=10h*/
0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00, /*"1"=11h*/
0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00, /*"2"=12h*/
0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00, /*"3"=13h*/
0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00, /*"4"=14h*/
0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00, /*"5"=15h*/
0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00, /*"6"=16h*/
0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00, /*"7"=17h*/
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, /*"8"=18h*/
0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00, /*"9"=19h*/
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00, /*":"=1Ah*/
0x00,0x00,0x56,0x36,0x00,0x00,0x00,0x00, /*";"=1Bh*/
0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00, /*"<"=1Ch*/
0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00, /*"="=1Dh*/
0x00,0x00,0x41,0x22,0x14,0x08,0x00,0x00, /*">"=1Eh*/
0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00, /*"?"=1Fh*/
0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00, /*"@"=20h*/
0x00,0x7E,0x11,0x11,0x11,0x7E,0x00,0x00, /*"A"=21h*/
0x00,0x41,0x7F,0x49,0x49,0x36,0x00,0x00, /*"B"=22h*/
0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00, /*"C"=23h*/
0x00,0x41,0x7F,0x41,0x41,0x3E,0x00,0x00, /*"D"=24h*/
0x00,0x7F,0x49,0x49,0x49,0x49,0x00,0x00, /*"E"=25h*/
0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00, /*"F"=26h*/
0x00,0x3E,0x41,0x41,0x49,0x7A,0x00,0x00, /*"G"=27h*/
0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00, /*"h"=28h*/
0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00, /*"I"=29h*/
0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00, /*"J"=2Ah*/
0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00, /*"K"=2Bh*/
0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00, /*"L"=2Ch*/
0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00, /*"M"=2Dh*/
0x00,0x7F,0x06,0x08,0x30,0x7F,0x00,0x00, /*"N"=2Eh*/
0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00, /*"O"=2Fh*/
0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00, /*"P"=30h*/
0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00, /*"Q"=31h*/
0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00, /*"R"=32h*/
0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00, /*"S"=33h*/
0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00, /*"T"=34h*/
0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00, /*"U"=35h*/
0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00, /*"V"=36h*/
0x00,0x7F,0x20,0x18,0x20,0x7F,0x00,0x00, /*"W"=37h*/
0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00, /*"X"=38h*/
0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x00, /*"Y"=39h*/
0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00, /*"Z"=3Ah*/
0x00,0x00,0x7F,0x41,0x41,0x00,0x00,0x00, /*"["=3Bh*/
0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00, /*"\"=3Ch*/
0x00,0x00,0x41,0x41,0x7F,0x00,0x00,0x00, /*"]"=3Dh*/
0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00, /*"^"=3Eh*/
0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00, /*"_"=3Fh*/
0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00, /*"`"=40h*/
0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00, /*"a"=41h*/
0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00, /*"b"=42h*/
0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x00, /*"c"=43h*/
0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00, /*"d"=44h*/
0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00, /*"e"=45h*/
0x00,0x00,0x08,0x7E,0x09,0x02,0x00,0x00, /*"f"=46h*/
0x00,0x0C,0x52,0x52,0x4C,0x3E,0x00,0x00, /*"g"=47h*/
0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00, /*"h"=48h*/
0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00, /*"i"=49h*/
0x00,0x20,0x40,0x44,0x3D,0x00,0x00,0x00, /*"j"=4Ah*/
0x00,0x00,0x7F,0x10,0x28,0x44,0x00,0x00, /*"k"=4Bh*/
0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x00, /*"l"=4Ch*/
0x00,0x7C,0x04,0x78,0x04,0x78,0x00,0x00, /*"m"=4Dh*/
0x00,0x7C,0x08,0x04,0x04,0x78,0x00,0x00, /*"n"=4Eh*/
0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00, /*"o'=4Fh*/
0x00,0x7E,0x0C,0x12,0x12,0x0C,0x00,0x00, /*"p"=50h*/
0x00,0x0C,0x12,0x12,0x0C,0x7E,0x00,0x00, /*"q"=51h*/
0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00, /*"r"=52h*/
0x00,0x58,0x54,0x54,0x54,0x64,0x00,0x00, /*"s"=53h*/
0x00,0x04,0x3F,0x44,0x40,0x20,0x00,0x00, /*"t"=54h*/
0x00,0x3C,0x40,0x40,0x3C,0x40,0x00,0x00, /*"u"=55h*/
0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00, /*"v"=56h*/
0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00, /*"w"=57h*/
0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00, /*"x"=58h*/
0x00,0x1C,0xA0,0xA0,0x90,0x7C,0x00,0x00, /*"y"=59h*/
0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00, /*"z"=5Ah*/
0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00, /*"{"=5Bh*/
0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x00, /*"|"=5Ch*/
0x00,0x00,0x41,0x36,0x08,0x00,0x00,0x00, /*"}"=5Dh*/
0x00,0x02,0x01,0x02,0x04,0x02,0x00,0x00, /*"~"=5Fh*/
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00 /*" "=0x60*/
};
__flash unsigned char FirstPage[1024]={
/*-- 调入了一幅图像:C:\Documents and Settings\freelover\桌面\未标题-1.bmp --*/
/*-- 宽度x高度=128x64 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x48,0x88,0x08,0x88,0x78,0x08,0x80,0x60,
0x3E,0xA0,0x20,0x20,0xA0,0x60,0x20,0x00,0x00,0x40,0x42,0x44,0xCC,0x00,0x00,0xF8,
0x08,0x04,0x04,0xF8,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,0x00,0x80,0x40,0xF0,0x0E,
0x08,0xC8,0x48,0x48,0x48,0xFE,0x48,0x48,0x48,0xCC,0x08,0x00,0x00,0x00,0x00,0xFC,
0x44,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0xFE,0x04,0x00,0x00,0x80,0x40,
0x20,0x10,0x10,0x10,0x20,0x70,0x00,0x10,0xF0,0x10,0x10,0x10,0x10,0xE0,0x00,0x00,
0x10,0xF0,0x10,0x10,0x10,0x10,0xE0,0x00,0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0x10,
0x10,0x00,0x00,0x00,0x20,0x20,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x19,0x06,0x05,0x08,0xB0,0x40,0x20,
0x18,0x07,0x18,0x20,0x40,0x80,0x80,0x00,0x00,0x80,0x40,0x20,0x1F,0x20,0x40,0x8F,
0x84,0x84,0x82,0xFF,0x80,0x88,0x90,0x8F,0x80,0x00,0x00,0x01,0x00,0x00,0xFF,0x00,
0x00,0x07,0x8C,0x54,0x24,0x5F,0x84,0x84,0x04,0x07,0x00,0x00,0x00,0x00,0xC0,0x3F,
0x04,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x84,0x04,0xFF,0x00,0x00,0x00,0x1F,0x60,
0x80,0x80,0x80,0x80,0x40,0x30,0x00,0x80,0xFF,0x82,0x02,0x0E,0x32,0xC1,0x80,0x00,
0x80,0xFF,0x82,0x82,0x82,0x83,0x44,0x38,0x00,0x00,0x73,0x82,0x81,0x81,0x81,0x42,
0x3C,0x00,0x00,0x00,0x80,0x80,0xFF,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x91,0x51,0x30,0x10,0x10,
0x90,0x50,0x10,0x10,0x00,0x01,0x10,0x10,0xF0,0x90,0x90,0x90,0x90,0x10,0xE0,0x00,
0x00,0xF0,0x00,0x00,0x00,0xC0,0x50,0x50,0x60,0x40,0xC0,0x40,0x60,0x50,0x51,0xC0,
0x01,0x01,0x00,0x00,0xE0,0x00,0x00,0x00,0x01,0xF1,0x01,0x00,0x00,0x01,0x00,0x00,
0x80,0x80,0xF0,0x80,0x80,0x01,0xE0,0x20,0x20,0xE1,0x00,0x00,0x00,0x00,0xE0,0x20,
0x20,0xA0,0x20,0x20,0x30,0xA0,0x20,0x20,0x20,0x20,0xE0,0x00,0xD0,0x10,0x10,0xF0,
0x00,0x00,0x80,0x40,0x30,0x40,0x80,0x00,0x00,0x00,0x80,0x80,0xF0,0x80,0x80,0xE0,
0x20,0x20,0x20,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x89,0x49,0x2D,0x8D,0x0B,0xF9,0x09,
0x08,0x2A,0x4C,0x98,0x00,0x00,0x04,0x03,0x84,0x48,0x30,0x0C,0x03,0x00,0x3F,0x00,
0x00,0xFF,0x00,0x00,0x40,0x5F,0x52,0x52,0x52,0x52,0xFF,0x52,0x52,0x52,0x52,0x5F,
0x40,0x00,0x00,0x80,0x7F,0x09,0x09,0x09,0x09,0x09,0x09,0xF9,0x01,0x01,0x00,0x00,
0x18,0x06,0xFF,0x04,0x08,0x80,0x7F,0x00,0x00,0xFF,0x00,0x00,0xC0,0x00,0x10,0x10,
0x12,0x94,0x99,0x52,0x30,0x1F,0x30,0x50,0x90,0x10,0x10,0x00,0x47,0x44,0x24,0x27,
0xFE,0x09,0x72,0x0A,0x72,0x82,0x60,0x1B,0x01,0x00,0x18,0x06,0xFF,0x04,0x88,0x7F,
0x05,0x89,0x51,0x71,0x8D,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0xF9,0x08,0x08,
0x08,0xF8,0x08,0x08,0x00,0x00,0x01,0x01,0x30,0x28,0x20,0xE0,0x3C,0x20,0x20,0x35,
0x29,0x20,0x20,0x00,0x00,0x40,0x40,0x50,0x50,0x50,0xFD,0xD0,0x50,0x70,0x50,0x48,
0x40,0x00,0x01,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x81,0x80,0x80,0x80,0x00,
0x80,0x80,0x81,0x01,0x81,0x80,0x00,0x00,0x00,0x80,0x81,0x81,0x00,0x00,0x01,0x01,
0x81,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x81,0x81,0x80,0x10,0xF0,0x81,0x81,
0x80,0x01,0x01,0x01,0x01,0x81,0x81,0x81,0x01,0x00,0x80,0x80,0x81,0x01,0x80,0x81,
0x81,0x00,0x00,0x80,0x80,0x81,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x21,0x11,0x0D,0x07,0x01,0x01,
0x01,0x3F,0x01,0x01,0x01,0x00,0x00,0x08,0x0C,0x26,0x23,0x30,0x17,0x1D,0x19,0x17,
0x31,0x20,0x20,0x00,0x00,0x04,0x04,0x02,0x3E,0x29,0x29,0x2A,0x2A,0x2A,0x3E,0x00,
0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x0F,0x10,0x10,0x10,0x09,0x00,
0x10,0x10,0x1F,0x11,0x10,0x00,0x00,0x00,0x09,0x14,0x12,0x12,0x1F,0x10,0x00,0x19,
0x12,0x12,0x14,0x09,0x00,0x40,0x41,0x66,0x18,0x06,0x01,0x00,0x00,0x1F,0x10,0x10,
0x10,0x0F,0x00,0x00,0x0F,0x10,0x10,0x10,0x0F,0x00,0x40,0x41,0x66,0x18,0x06,0x01,
0x00,0x00,0x0F,0x12,0x12,0x12,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x02,0x0E,0xF2,0x00,0xF2,0x0E,0x02,0x02,0xFE,0x22,0x22,
0x72,0x06,0x00,0x02,0xFE,0x12,0x32,0xD2,0x0C,0x00,0x00,0x00,0x18,0x18,0x00,0x00,
0x00,0x00,0x04,0x04,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,
0x04,0x02,0x02,0x04,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x02,0x03,0x02,0x02,
0x02,0x03,0x00,0x02,0x03,0x02,0x00,0x00,0x03,0x02,0x00,0x00,0x03,0x03,0x00,0x00,
0x00,0x00,0x02,0x02,0x03,0x02,0x02,0x00,0x00,0x03,0x03,0x00,0x00,0x00,0x00,0x00,
0x01,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
void Nop(unsigned int k)
{
while(k--);
}
void delay(unsigned int k)
{
unsigned int a,b;
for(a=0;a<k;a++)
for(b=0;b<255;b++);
}
//检查屏状态
void CheckState_L(void)
{
unsigned char dat;
LCD_CS1_H;
LCD_CS2_L;
LCD_COM;
LCD_R;
do{
DDRA =0xff;
PORTA=0xff;
LCD_EN;
DDRA =0x00;
Nop(2);
dat=(PINA&0xff);
LCD_DIS;
dat &=0x90; //仅当第4rest,7busy 为0时才可操作
}while(dat==0x90);
}
//写命令
void Write_Command_L(unsigned char cmd)
{
CheckState_L();
LCD_W;
LCD_COM;
DDRA =0xff;
PORTA=cmd;
LCD_EN;
LCD_DIS;
}
//写数据
void Write_Data_L(unsigned char dat)
{
CheckState_L();
LCD_W;
LCD_DATA;
DDRA =0xff;
PORTA=dat;
LCD_EN;
LCD_DIS;
}
void CheckState_R(void)
{
unsigned char dat;
LCD_CS1_L;
LCD_CS2_H;
LCD_COM;
LCD_R;
do{
DDRA =0xff;
PORTA=0xff;
LCD_EN;
DDRA =0x00;
Nop(2);
dat=(PINA&0xff);
LCD_DIS;
dat &=0x90; //仅当第4rest,7busy 为0时才可操作
}while(dat==0x90);
}
//写命令
void Write_Command_R(unsigned char cmd)
{
CheckState_R();
LCD_W;
LCD_COM;
DDRA =0xff;
PORTA=cmd;
LCD_EN;
LCD_DIS;
}
//写数据
void Write_Data_R(unsigned char dat)
{
CheckState_R();
LCD_W;
LCD_DATA;
DDRA =0xff;
PORTA=dat;
LCD_EN;
LCD_DIS;
}
/*读显示数据
unsigned char Read_Data(void)
{
unsigned char dat;
LCD_DATA;
LCD_R;
DDRA =0XFF;
PORTA=0xff;
LCD_EN;
Nop(10);
dat=(PINB&0xff);
LCD_DIS;
return(dat);
}
*/
void CLEAR(void)
{
unsigned char add_x,add_y;
for(add_y =0xb8;add_y!=0xC0;add_y++) //以页地址作为循环量
{
Write_Command_L(add_y); // 页地址
Write_Command_L(0x40); // 列地址设置
for(add_x =0;add_x <64;add_x++)
{
Write_Data_L(0x00);
}
Write_Command_R(add_y); // 页地址
Write_Command_R(0x40); // 列地址设置
for(add_x =0;add_x <64;add_x++)
{
Write_Data_R(0x00);
}
}
}
void Write_char(unsigned char xpos,unsigned char ypos,unsigned char lcddata) //一次写入一个字节
{
if(xpos<128 && ypos<8)
{
if( ( xpos & 0x40 )== 0 ) // 左屏
{
Write_Command_L( 0xb8 | ypos ); //ypos 为页值
Write_Command_L( 0x40 | xpos); //xpos 为列值
Write_Data_L( lcddata );
}
else // 右屏
{
Write_Command_R( 0xb8 | ypos );
Write_Command_R( 0x40 | xpos);
Write_Data_R( lcddata );
}
}
}
void lcd_putchar8x8( unsigned char x,unsigned char y,unsigned char ch ) //显示8×8字符
{
unsigned char i;
for( i = 0; i < 8; i ++ )
{
Write_char( x+i, y, AscII[ch-32] );
}
}
void displaystr(unsigned char x,unsigned char y,unsigned char *str)
{
unsigned char temp;
for(;*str!=0;str++)
{
temp =*str;
lcd_putchar8x8(x,y,temp);
x +=8;
if(x>=128)
return;
}
}
/*------------------显示12864图片---------------------------*/
void Disp_Img(unsigned char __flash *img)
{
unsigned char i,k;
for(k=0;k<8;k++)
{
delay(10);
Write_Command_L(0xb8+k);
Write_Command_L(0x40+0);
for(i=0;i<64;i++)
Write_Data_L(img[k*128+i]);
delay(10);
Write_Command_R(0xb8+k);
Write_Command_R(0x40+0);
for(i=64;i<128;i++)
Write_Data_R(img[k*128+i]);
}
}
/*************************************
初始化函数
************************************/
void InitLcd(void)
{
LCD_RST_H;
LCD_W;
Nop(2000);
Write_Command_L(0x3e); // 关显示
Write_Command_R(0x3e); // 关显示
Write_Command_L(0xc0); // 显示起始行为0
Write_Command_R(0xc0); // 显示起始行为0
Write_Command_L(0x3f); // 开显示
Write_Command_R(0x3f); // 开显示
CLEAR();
}
void InitTimer0(void)
{
TCCR0 = 0x00; //stop/*定时器停止,TCCR0寄存器完全控制timer0的运行情况,详细可参考数据手册。*/
TCNT0 =0x7f;
TCCR0 =0X02;//start timer/*定时器开始*/8预分频
TIMSK =0X01;
SREG |=0X80;
}
unsigned int Count;
unsigned char Hz;
#pragma vector=TIMER0_OVF_vect
__interrupt void Timer0(void)
{
TCNT0=Hz;
PORTC =~PORTC ;
}
int main( void )
{
unsigned char p;
InitTimer0();
InitLcd();
Disp_Img(FirstPage);
delay(5000);
CLEAR();
displaystr(0,0,"abcdefghijklmnop");
displaystr(0,2,"qrstuvwxyz,';:.,");
displaystr(0,4,"ABCDEFGHIJKLMNOP");
displaystr(0,6,"QRSTUVWXYZ[]}{/~");
displaystr(0,8,"!@#$%^&*()_+-><?");
while(1);
} |