ATmega16L驱动ILI9325/9328
首先是硬件连线:PB----8位数据口
PA0--- 复位信号RESET
PA1---片选CS
PA2----寄存器选择信号RS
PA3---写信号WR
PA4---读信号RD
文件名:Type.h,主要定义一些数据变量的别名
/****************************************Copyright (c)************************************************** ** Southeast University **--------------File Info------------------------------------------------------------------------------- ** File Name: Type.h ** Last modified Date: 2012-03-23 ** Last Version: 1.0 ** Description: 定义数据类型别名 **------------------------------------------------------------------------------------------------------ ** Created By: JianGe ** Created date: 2012-03-23 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ */ #ifndef __TYPE_H__ #define __TYPE_H__ /******************************************************************************************************** * Date types(Compiler specific) 数据类型(和编译器相关) * ********************************************************************************************************/ typedef unsigned char uint8; // Unsigned 8 bit quantity 无符号8位整型变量 typedef unsigned char uchar; // Unsigned 8 bit quantity 无符号8位整型变量 typedef signed char int8; // Signed 8 bit quantity 有符号8位整型变量 typedef unsigned short uint16; // Unsigned 16 bit quantity 无符号16位整型变量 typedef signed short int16; // Signed 16 bit quantity 有符号16位整型变量 typedef unsigned int uint32; // Unsigned 32 bit quantity 无符号32位整型变量 typedef unsigned int uint; // Unsigned 32 bit quantity 无符号32位整型变量 typedef signed int int32; // Signed 32 bit quantity 有符号32位整型变量 typedef float fp32; // Single precision floating point 单精度浮点数(32位长度) typedef double fp64; // Double precision floating point 双精度浮点数(64位长度) #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifndef NULL #define NULL 0 #endif #endif /********************************************************************************************************* * End Of File * *********************************************************************************************************/
文件名:USART.h,串口操作函数的声明
/****************************************Copyright (c)************************************************** ** Southeast University **--------------File Info------------------------------------------------------------------------------- ** File Name: USART.h ** Last modified Date: 2012-03-23 ** Last Version: 1.0 ** Description: 串口函数声明 **------------------------------------------------------------------------------------------------------ ** Created By: JianGe ** Created date: 2012-03-23 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ */ #ifndef _USART_H #define _USART_H #include "Type.h" #define BAUD 9600 //波特率设置 #define CRYSTAL 4000000 //11059200 //晶振频率 #define BAUD_SET (uint16)((uint32)CRYSTAL/(16*(uint32)BAUD)-1) #define BAUD_H (uint8)(BAUD_SET>>8) #define BAUD_L (uint8)(BAUD_SET) #define FE_EER BIT(FE) //帧接收错误 #define PE_EER BIT(PE) //校验错误 #define DATA_OVER BIT(DOR) //接收溢出错误 #define UDR_EMPTY BIT(UDRE) //数据寄存器空 #define USAT_TX_EN UCSRB|=BIT(TXEN) //使能USART发送 #define USAT_TX_NO_EN UCSRB&=~BIT(TXEN) #define USAT_RX_EN UCSRB|=BIT(RXEN) //使能USART接收 #define USAT_RX_NO_EN UCSRB&=~BIT(RXEN) extern void USART_Init(void); extern void Uart_Transmit(unsigned char i); extern unsigned char Uart_Receive( void ); #endif /********************************************************************************************************* * End Of File * *********************************************************************************************************/
文件名:Delay.h,延时函数的声明
/****************************************Copyright (c)************************************************** ** Southeast University **--------------File Info------------------------------------------------------------------------------- ** File Name: Delay.h ** Last modified Date: 2012-03-23 ** Last Version: 1.0 ** Description: 延时函数声明 **------------------------------------------------------------------------------------------------------ ** Created By: JianGe ** Created date: 2012-03-23 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ */ # ifndef DELAY_H_H_ # define DELAY_H_H_ # define DELAY_US asm("nop"); asm("nop"); asm("nop"); asm("nop");\ asm("nop"); asm("nop"); asm("nop"); asm("nop"); extern void Delay_nUS(unsigned int n); extern void Delay_MS(void); extern void Delay_nMS(unsigned int n); # endif /********************************************************************************************************* * End Of File * *********************************************************************************************************/
文件名:LCDDriver.h,LCD驱动函数和应用函数的声明
/****************************************Copyright (c)************************************************** ** Southeast University **--------------File Info------------------------------------------------------------------------------- ** File Name: LCD_Driver.h ** Last modified Date: 2012-03-24 ** Last Version: 1.0 ** Description: LCD驱动函数声明 **------------------------------------------------------------------------------------------------------ ** Created By: JianGe ** Created date: 2012-03-24 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ */ # ifndef LCD_DRIVER_H_H_ # define LCD_DRIVER_H_H_ # include "Type.h" # include <iom16v.h> extern void LCD_Port_Init(void); extern void LCD_WriteCmd(uint32 regID); extern void LCD_WriteData(uint32 data); extern void LCD_WriteReg(uint32 regID, uint32 regData); extern unsigned int LCD_ReadReg(uint32 regID); extern void LCD_ILI9325_Init(void); extern void LCD_SetWindow(unsigned int x0, unsigned int x1, unsigned int y0, unsigned int y1); extern void LCD_ClearScreen(unsigned int color); extern void LCD_Fill_Rectangle(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color); extern unsigned char Get_CharOffset(unsigned char char_data); extern void Set_CharWindow(unsigned int lineNum, unsigned int rowNum); extern void LCD_WriteChar(unsigned int lineNum, unsigned int rowNum, unsigned int charColor, unsigned int bkColor, unsigned char chChar) extern void LCD_WriteString(unsigned char lineNum, unsigned char rowNum, unsigned int charColor, unsigned int bkColor, unsigned char *p_str) # endif /********************************************************************************************************* * End Of File * *********************************************************************************************************/
文件名:LCD_Font.h LCD字体库的声明
/****************************************Copyright (c)************************************************** ** Southeast University **--------------File Info------------------------------------------------------------------------------- ** File Name: LCD_Font.h ** Last modified Date: 2012-03-27 ** Last Version: 1.0 ** Description: LCD显示字符的字节表 **------------------------------------------------------------------------------------------------------ ** Created By: JianGe ** Created date: 2012-03-27 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ */ # ifndef LCD_FONT_H_H_ # define LCD_FONT_H_H_ //常用ASCII字符码表 const unsigned char Letter[][16] = { //第一栏从' '到 '?' {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/ {0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x18,0x18,0x00,0x00},/*"!",1*/ {0x00,0x12,0x36,0x24,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/ {0x00,0x00,0x00,0x24,0x24,0x24,0xFE,0x48,0x48,0x48,0xFE,0x48,0x48,0x48,0x00,0x00},/*"#",3*/ {0x00,0x00,0x10,0x38,0x54,0x54,0x50,0x30,0x18,0x14,0x14,0x54,0x54,0x38,0x10,0x10},/*"$",4*/ {0x00,0x00,0x00,0x44,0xA4,0xA8,0xA8,0xA8,0x54,0x1A,0x2A,0x2A,0x2A,0x44,0x00,0x00},/*"%",5*/ {0x00,0x00,0x00,0x30,0x48,0x48,0x48,0x50,0x6E,0xA4,0x94,0x88,0x89,0x76,0x00,0x00},/*"&",6*/ {0x00,0x60,0x60,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/ {0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00},/*"(",8*/ {0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00},/*")",9*/ {0x00,0x00,0x00,0x00,0x10,0x10,0xD6,0x38,0x38,0xD6,0x10,0x10,0x00,0x00,0x00,0x00},/*"*",10*/ {0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x10,0x00,0x00,0x00},/*"+",11*/ {0x00,0x60,0x60,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",12*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00},/*".",14*/ {0x00,0x00,0x01,0x02,0x02,0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x40,0x00},/*"/",15*/ {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",16*/ {0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"1",17*/ {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",18*/ {0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"3",19*/ {0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00},/*"4",20*/ {0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",21*/ {0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"6",22*/ {0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",23*/ {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",24*/ {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00},/*"9",25*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",26*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x20},/*";",27*/ {0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00},/*"<",28*/ {0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00},/*"=",29*/ {0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00},/*">",30*/ {0x00,0x00,0x00,0x3C,0x42,0x42,0x62,0x02,0x04,0x08,0x08,0x00,0x18,0x18,0x00,0x00},/*"?",31*/ //第二栏从'@'开始 {0x00,0x00,0x00,0x38,0x44,0x5A,0xAA,0xAA,0xAA,0xAA,0xB4,0x42,0x44,0x38,0x00,0x00},/*"@",32*/ {0x00,0x00,0x00,0x10,0x10,0x18,0x28,0x28,0x24,0x3C,0x44,0x42,0x42,0xE7,0x00,0x00},/*"A",33*/ {0x00,0x00,0x00,0xF8,0x44,0x44,0x44,0x78,0x44,0x42,0x42,0x42,0x44,0xF8,0x00,0x00},/*"B",34*/ {0x00,0x00,0x00,0x3E,0x42,0x42,0x80,0x80,0x80,0x80,0x80,0x42,0x44,0x38,0x00,0x00},/*"C",35*/ {0x00,0x00,0x00,0xF8,0x44,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x44,0xF8,0x00,0x00},/*"D",36*/ {0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x42,0x42,0xFC,0x00,0x00},/*"E",37*/ {0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x40,0x40,0xE0,0x00,0x00},/*"F",38*/ {0x00,0x00,0x00,0x3C,0x44,0x44,0x80,0x80,0x80,0x8E,0x84,0x44,0x44,0x38,0x00,0x00},/*"G",39*/ {0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"H",40*/ {0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"I",41*/ {0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x88,0xF0},/*"J",42*/ {0x00,0x00,0x00,0xEE,0x44,0x48,0x50,0x70,0x50,0x48,0x48,0x44,0x44,0xEE,0x00,0x00},/*"K",43*/ {0x00,0x00,0x00,0xE0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x42,0xFE,0x00,0x00},/*"L",44*/ {0x00,0x00,0x00,0xEE,0x6C,0x6C,0x6C,0x6C,0x54,0x54,0x54,0x54,0x54,0xD6,0x00,0x00},/*"M",45*/ {0x00,0x00,0x00,0xC7,0x62,0x62,0x52,0x52,0x4A,0x4A,0x4A,0x46,0x46,0xE2,0x00,0x00},/*"N",46*/ {0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x44,0x38,0x00,0x00},/*"O",47*/ {0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x42,0x7C,0x40,0x40,0x40,0x40,0xE0,0x00,0x00},/*"P",48*/ {0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0xB2,0xCA,0x4C,0x38,0x06,0x00},/*"Q",49*/ {0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x7C,0x48,0x48,0x44,0x44,0x42,0xE3,0x00,0x00},/*"R",50*/ {0x00,0x00,0x00,0x3E,0x42,0x42,0x40,0x20,0x18,0x04,0x02,0x42,0x42,0x7C,0x00,0x00},/*"S",51*/ {0x00,0x00,0x00,0xFE,0x92,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00},/*"T",52*/ {0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"U",53*/ {0x00,0x00,0x00,0xE7,0x42,0x42,0x44,0x24,0x24,0x28,0x28,0x18,0x10,0x10,0x00,0x00},/*"V",54*/ {0x00,0x00,0x00,0xD6,0x92,0x92,0x92,0x92,0xAA,0xAA,0x6C,0x44,0x44,0x44,0x00,0x00},/*"W",55*/ {0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00},/*"X",56*/ {0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00},/*"Y",57*/ {0x00,0x00,0x00,0x7E,0x84,0x04,0x08,0x08,0x10,0x20,0x20,0x42,0x42,0xFC,0x00,0x00},/*"Z",58*/ {0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00},/*"[",59*/ {0x00,0x00,0x40,0x40,0x20,0x20,0x10,0x10,0x10,0x08,0x08,0x04,0x04,0x04,0x02,0x02},/*"\",60*/ {0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00},/*"]",61*/ {0x00,0x1C,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",63*/ //第三栏从'''开始 {0x00,0x60,0x60,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",64*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x1E,0x22,0x42,0x42,0x3F,0x00,0x00},/*"a",65*/ {0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x64,0x58,0x00,0x00},/*"b",66*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x40,0x40,0x40,0x22,0x1C,0x00,0x00},/*"c",67*/ {0x00,0x00,0x00,0x06,0x02,0x02,0x02,0x1E,0x22,0x42,0x42,0x42,0x26,0x1B,0x00,0x00},/*"d",68*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x40,0x40,0x42,0x3C,0x00,0x00},/*"e",69*/ {0x00,0x00,0x00,0x0F,0x11,0x10,0x10,0x7E,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"f",70*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x44,0x44,0x38,0x40,0x3C,0x42,0x42,0x3C},/*"g",71*/ {0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"h",72*/ {0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"i",73*/ {0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x1C,0x04,0x04,0x04,0x04,0x04,0x04,0x44,0x78},/*"j",74*/ {0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x4E,0x48,0x50,0x68,0x48,0x44,0xEE,0x00,0x00},/*"k",75*/ {0x00,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"l",76*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x49,0x49,0x49,0x49,0x49,0xED,0x00,0x00},/*"m",77*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"n",78*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"o",79*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD8,0x64,0x42,0x42,0x42,0x44,0x78,0x40,0xE0},/*"p",80*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x22,0x42,0x42,0x42,0x22,0x1E,0x02,0x07},/*"q",81*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEE,0x32,0x20,0x20,0x20,0x20,0xF8,0x00,0x00},/*"r",82*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x42,0x40,0x3C,0x02,0x42,0x7C,0x00,0x00},/*"s",83*/ {0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x7C,0x10,0x10,0x10,0x10,0x10,0x0C,0x00,0x00},/*"t",84*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC6,0x42,0x42,0x42,0x42,0x46,0x3B,0x00,0x00},/*"u",85*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x10,0x10,0x00,0x00},/*"v",86*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD7,0x92,0x92,0xAA,0xAA,0x44,0x44,0x00,0x00},/*"w",87*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6E,0x24,0x18,0x18,0x18,0x24,0x76,0x00,0x00},/*"x",88*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x18,0x10,0x10,0xE0},/*"y",89*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x44,0x08,0x10,0x10,0x22,0x7E,0x00,0x00},/*"z",90*/ {0x00,0x03,0x04,0x04,0x04,0x04,0x04,0x08,0x04,0x04,0x04,0x04,0x04,0x04,0x03,0x00},/*"{",91*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",92*/ {0x00,0x60,0x10,0x10,0x10,0x10,0x10,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x60,0x00},/*"}",93*/ {0x30,0x4C,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/ {0x00,0x1C,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",95*/ }; # endif /********************************************************************************************************* * End Of File * *********************************************************************************************************/
文件名: Delay.c,延时函数的实现
/****************************************Copyright (c)************************************************** ** Southeast University **--------------File Info------------------------------------------------------------------------------- ** File Name: Delay.c ** Last modified Date: 2012-03-23 ** Last Version: 1.0 ** Description: 延时函数实现 **------------------------------------------------------------------------------------------------------ ** Created By: JianGe ** Created date: 2012-03-23 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ */ #include "Delay.h" #include "Type.h" /********************************************************************************************************* ** Function name: Delay_nUS ** Descriptions: 延时n微秒 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void Delay_nUS(uint32 n) { uint32 i=0; for(i=0; i<n; i++) { DELAY_US; } } /********************************************************************************************************* ** Function name: Delay_MS ** Descriptions: 延时1毫秒 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void Delay_MS(void) { uint32 i=0; for(i=0; i<1000; i++) { DELAY_US; } } /********************************************************************************************************* ** Function name: Delay_nMS ** Descriptions: 延时n毫秒 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void Delay_nMS(uint32 n) { uint32 i=0; for(i=0; i<n; i++) { Delay_MS(); } } /********************************************************************************************************* * End Of File * *********************************************************************************************************/
文件名:USART.c 串口调试函数的实现
/****************************************Copyright (c)************************************************** ** Southeast University **--------------File Info------------------------------------------------------------------------------- ** File Name: USART.c ** Last modified Date: 2012-03-23 ** Last Version: 1.0 ** Description: 串口函数实现 **------------------------------------------------------------------------------------------------------ ** Created By: JianGe ** Created date: 2012-03-23 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ */ #include <iom16v.h> #include "USART.h" /*串口初始化函数*/ void USART_Init(void) { UCSRA = 0x02; /*倍速*/ UCSRB = 0x18; /*允许接收和发送*/ UCSRC = 0x06; /*8位数据*/ UBRRH = 0x00; //UBRRL = 12; /*9600*/ //UBRRL = 103; //11.0592M下9600 UBRRL = 207; //16MHz下9600 }/*数据发送,查询方式*/ void Uart_Transmit(unsigned char i) { while (!(UCSRA & (1<<UDRE))); /* 等待发送缓冲器为空*/ UDR = i; /* 发送数据*/ } /*数据接收,查询方式*/ unsigned char Uart_Receive( void ) { while (!(UCSRA & (1<<RXC))); /* 等待接收数据*/ return UDR; /* 获取并返回数据*/ } /********************************************************************************************************* * End Of File * *********************************************************************************************************/
文件名:LCDDriver.c LCD驱动函数以及上层函数的实现
/****************************************Copyright (c)************************************************** ** Southeast University **--------------File Info------------------------------------------------------------------------------- ** File Name: LCDDriver.c ** Last modified Date: 2012-04-12 ** Last Version: 1.0 ** Description: LCD驱动函数的实现 **------------------------------------------------------------------------------------------------------ ** Created By: JianGe ** Created date: 2012-03-24 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ */ # include "Delay.h" # include <iom16v.h> # include <macros.h> # include "USART.h" # include "LCD_Font.h" # include "Type.h" ///////////屏显示参数设置/////////////// //设置屏显示像素大小 # define X_SIZE 240 # define Y_SIZE 320 //x和y的最大坐标值,坐标原点为(0, 0) # define X_END (X_SIZE - 1) # define Y_END (Y_SIZE - 1) //一个字符x*y的分别大小 # define CHAR_X_SIZE 8 # define CHAR_Y_SIZE 16 //横坐标能显示的字符数X_SIZE/CHAR_X_SIZE # define CHAR_X_NUM 30 //纵坐标能显示的字符数Y_SIZE/CHAR_Y_SIZE # define CHAR_Y_NUM 20 //////////////////////////////////////// //LCD控制端口动作宏定义 # define LCD_CS_BIT PA1 # define LCD_RS_BIT PA2 # define LCD_WR_BIT PA3 # define LCD_RD_BIT PA4 # define LCD_REST_BIT PA0 # define LCD_CLT_PORT PORTA # define LCD_CLT_PIN PINA # define LCD_CLT_DDR DDRA # define LCD_CS_L LCD_CLT_PORT &= ~BIT(LCD_CS_BIT) # define LCD_CS_H LCD_CLT_PORT |= BIT(LCD_CS_BIT) # define LCD_RS_L LCD_CLT_PORT &= ~BIT(LCD_RS_BIT) # define LCD_RS_H LCD_CLT_PORT |= BIT(LCD_RS_BIT) # define LCD_WR_L LCD_CLT_PORT &= ~BIT(LCD_WR_BIT) # define LCD_WR_H LCD_CLT_PORT |= BIT(LCD_WR_BIT) # define LCD_RD_L LCD_CLT_PORT &= ~BIT(LCD_RD_BIT) # define LCD_RD_H LCD_CLT_PORT |= BIT(LCD_RD_BIT) # define LCD_REST_L LCD_CLT_PORT &= ~BIT(LCD_REST_BIT) # define LCD_REST_H LCD_CLT_PORT |= BIT(LCD_REST_BIT) //8位数据口 # define DATA_H PB0 # define LCD_DATA_PORT PORTB # define LCD_DATA_DDR DDRB # define LCD_DATA_PIN PINB # define LCD_DATA_IN DDRB = 0x00 # define LCD_DATA_OUT DDRB = 0xFF //读GRAM时需要一个虚晃的读(Dummy Read) # define DUMMY_READ() LCD_RD_L;LCD_RD_H;LCD_RD_L;LCD_RD_H; //片选,开始9328的某种操作前调用 # define LCD_SELECT() LCD_CS_L //片选,结束9328的某项操作后调用 # define LCD_DIS_SELECT() LCD_CS_H /********************************************************************************************************* ** Function name: LCD_Port_Init ** Descriptions: LCD的控制端口和数据端口的初始化 ** input parameters: 寄存器地址regID ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void LCD_Port_Init(void) { LCD_DATA_OUT; LCD_DATA_PORT = 0xFF; LCD_CLT_DDR = 0xFF; LCD_CS_H; LCD_RS_H; LCD_WR_H; LCD_RD_H; LCD_REST_H; } /********************************************************************************************************* ** Function name: LCD_WriteCmd ** Descriptions: 写寄存器命令,选择一个寄存器 ** input parameters: 寄存器地址regID ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ /////////////////////////////////////////////////////////////////////////////////////////////////////// // nCS ----\__________________________________________/--------------------------- // // RS ------\______________________________/------------------------------------ // // nRD ---------------------------------------------------------------------------- // // nWR --------\______/----------\_____/------------------------------------------- // // DB[10:17] ----[寄存器高8位]-----[寄存器低8位]-------------------------------------------// //////////////////////////////////////////////////////////////////////////////////////////////////////// void LCD_WriteCmd(uint32 regID) { LCD_RS_L; LCD_DATA_PORT = regID>>8; LCD_WR_L; LCD_WR_H; LCD_DATA_PORT = regID; LCD_WR_L; LCD_WR_H; LCD_RS_H; } /********************************************************************************************************* ** Function name: LCD_WriteData ** Descriptions: 向LCD写数据 ** input parameters: 待写入的数据data ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ //////////////////////////////////////////////////////////////////////////////////////////////////// // nCS ----\__________________________________________/-----------------------------// // RS -----------------------------------------------------------------------------// // nRD ------------------------------------------------------------------------- // // nWR --------\______/--------\_____/----------------------------------------- // // DB[10:17] -----[数据高8位]----- [数据低8位]------------------------------------------- // ///////////////////////////////////////////////////////////////////////////////////////////////////// void LCD_WriteData(uint32 data) { LCD_DATA_PORT = data>>8; LCD_WR_L; LCD_WR_H; LCD_DATA_PORT = data; LCD_WR_L; LCD_WR_H; } /********************************************************************************************************* ** Function name: LCD_WriteReg ** Descriptions: 向一个寄存器写入数据 ** input parameters: 寄存器地址:regID 待写入的数据regData ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ //////////////////////////////////////////////////////////////////////////////////////////////////// // nCS ----\_____________________________________________________________/--------// // RS ----\____________________________/-----------------------------------------// // nRD ------------------------------------------------------------------------- // // nWR ------\______/--------\_____/--------\______/-----\______/---------------- // // DB[10:17] ---[寄存器高8位]---[寄存器低8位]---[数据高8位]----[数据低8位]--------------- // ///////////////////////////////////////////////////////////////////////////////////////////////////// void LCD_WriteReg(uint32 regID, uint32 regData) { LCD_RS_L; LCD_DATA_PORT = regID>>8; LCD_WR_L; LCD_WR_H; LCD_DATA_PORT = regID; LCD_WR_L; LCD_WR_H; LCD_RS_H; LCD_DATA_PORT = regData>>8; LCD_WR_L; LCD_WR_H; LCD_DATA_PORT = regData; LCD_WR_L; LCD_WR_H; } /********************************************************************************************************* ** Function name: LCD_ReadReg ** Descriptions: 读取指定寄存器的数据 ** input parameters: 寄存器地址:regID ** output parameters: 无 ** Returned value: 读出数据(16位) *********************************************************************************************************/ //////////////////////////////////////////////////////////////////////////////////////////////////// // nCS ----\_____________________________________________________________/--------// // RS ----\____________________________/-----------------------------------------// // nRD -----------------------------------\_____/------\_____/------------------ // // nWR ------\______/--------\_____/---------------------------------------------- // // DB[10:17] ---[寄存器高8位]--[寄存器低8位]--[数据高8位]--[数据低8位]--------------- // ///////////////////////////////////////////////////////////////////////////////////////////////////// unsigned int LCD_ReadReg(uint32 regID) { uint32 regData; LCD_WriteCmd(regID); LCD_DATA_IN; LCD_RS_H; LCD_RD_L; LCD_RD_H; regData = LCD_DATA_PIN; regData = regData << 8; LCD_RD_L; LCD_RD_H; regData |= LCD_DATA_PIN; LCD_WR_L; LCD_WR_H; LCD_DATA_OUT; return regData; } /********************************************************************************************************* ** Function name: LCD_ILI9325_Init ** Descriptions: 9325/28内部寄存器的初始化 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void LCD_ILI9325_Init(void) { uint32 ID = 0x0000; LCD_Port_Init(); LCD_REST_L; //复位 Delay_nMS(50); LCD_REST_H; Delay_nMS(50); LCD_SELECT(); ID = LCD_ReadReg(0x0000); // 读LCD的ID,这里是9328 Uart_Transmit(ID>>8); //串口观察 Uart_Transmit(ID); LCD_WriteReg(0x0001,0x0100); LCD_WriteReg(0x0002,0x0700); LCD_WriteReg(0x0003,0x1030); //转换RGB至GBR,水平扫描 LCD_WriteReg(0x0004,0x0000); LCD_WriteReg(0x0008,0x0207); LCD_WriteReg(0x0009,0x0000); LCD_WriteReg(0x000A,0x0000); LCD_WriteReg(0x000C,0x0000); LCD_WriteReg(0x000D,0x0000); LCD_WriteReg(0x000F,0x0000); //power on sequence VGHVGL LCD_WriteReg(0x0010,0x0000); LCD_WriteReg(0x0011,0x0007); LCD_WriteReg(0x0012,0x0000); LCD_WriteReg(0x0013,0x0000); //vgh LCD_WriteReg(0x0010,0x1290); LCD_WriteReg(0x0011,0x0227); //vregiout LCD_WriteReg(0x0012,0x001d); //0x001b //vom amplitude LCD_WriteReg(0x0013,0x1500); //vom H LCD_WriteReg(0x0029,0x0018); LCD_WriteReg(0x002B,0x000D); //gamma LCD_WriteReg(0x0030,0x0004); LCD_WriteReg(0x0031,0x0307); LCD_WriteReg(0x0032,0x0002);// 0006 LCD_WriteReg(0x0035,0x0206); LCD_WriteReg(0x0036,0x0408); LCD_WriteReg(0x0037,0x0507); LCD_WriteReg(0x0038,0x0204);//0200 LCD_WriteReg(0x0039,0x0707); LCD_WriteReg(0x003C,0x0405);// 0504 LCD_WriteReg(0x003D,0x0F02); //ram LCD_WriteReg(0x0050,0x0000); LCD_WriteReg(0x0051,0x00EF); LCD_WriteReg(0x0052,0x0000); LCD_WriteReg(0x0053,0x013F); LCD_WriteReg(0x0060,0xA700); LCD_WriteReg(0x0061,0x0001); LCD_WriteReg(0x006A,0x0000); // LCD_WriteReg(0x0080,0x0000); LCD_WriteReg(0x0081,0x0000); LCD_WriteReg(0x0082,0x0000); LCD_WriteReg(0x0083,0x0000); LCD_WriteReg(0x0084,0x0000); LCD_WriteReg(0x0085,0x0000); // LCD_WriteReg(0x0090,0x0010); LCD_WriteReg(0x0092,0x0600); LCD_WriteReg(0x0093,0x0003); LCD_WriteReg(0x0095,0x0110); LCD_WriteReg(0x0097,0x0000); LCD_WriteReg(0x0098,0x0000); LCD_WriteReg(0x0007,0x0133); LCD_DIS_SELECT(); } /********************************************************************************************************* ** Function name: LCD_SetWindow ** Descriptions: 定义刷屏窗口 ** input parameters: 起始坐标 (x0,y0),终止坐标(x1,y1) ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ static void LCD_SetWindow(unsigned int x0, unsigned int x1, unsigned int y0, unsigned int y1) { LCD_WriteReg(0x0050,x0); LCD_WriteReg(0x0051,x1); LCD_WriteReg(0x0052,y0); LCD_WriteReg(0x0053,y1); LCD_WriteReg(0x0020,x0); LCD_WriteReg(0x0021,y0); LCD_WriteCmd(0x0022); //GRAM寄存器,之后可以写GRAM缓冲区 } /*******************************************************************************************************************/ /*******************************************************************************************************************/ /**************************************************以下为LCD的应用函数**********************************************/ /*******************************************************************************************************************/ /*******************************************************************************************************************/ /********************************************************************************************************* ** Function name: LCD_ClearScreen ** Descriptions: 刷整屏为一种颜色 ** input parameters: 颜色的RGB值color ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void LCD_ClearScreen(unsigned int color) { unsigned int i,j; LCD_SELECT(); //选择9328 LCD_SetWindow(0,240,0,320); //320x240的屏 for (i=0;i<320;i++) { for (j=0;j<240;j++) { LCD_WriteData(color); //向GRAM写入RGB数据 } } LCD_DIS_SELECT(); //操作完毕 } /********************************************************************************************************* ** Function name: LCD_Fill ** Descriptions: 填充一个矩形区域 ** input parameters: 矩形起始坐标----(x0,y0),矩形终点坐标--(x1,y1) ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ // void LCD_Fill_Rectangle(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color) { unsigned long i; LCD_SELECT(); //选择9328 LCD_SetWindow(x0, x1, y0, y1); for(i=0; i < (x1 - x0 + 1)*(y1 - y0 + 1); i++) { LCD_WriteData(color); //填充颜色 } LCD_DIS_SELECT(); //操作完毕 } /********************************************************************************************************* ** Function name: Get_CharOffset ** Descriptions: 获取字节的偏移量 ** input parameters: 输入字节 ** output parameters: 无 ** Returned value: 偏移量 *********************************************************************************************************/ unsigned char Get_CharOffset(unsigned char char_data) { if(char_data >= ' ' && char_data <= '}') { char_data -= ' '; //字符偏移从空格开始 } else { char_data = ' '; //如无匹配字符以空格代替 } return char_data; //返回字符所在字符表的位置 } /********************************************************************************************************* ** Function name: Set_CharWindow ** Descriptions: 设置字节窗口 ** input parameters: 每个字符8X16像素,共30行20列,lineNum----字符所在行号,rowLine----字符所在列号 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ //例如显示'2'这个字节窗口,为一个8X16的像素矩形 // _ _ _ _ _ _ _ _ , // _ _ _ _ _ _ _ _ , // _ _ _ _ _ _ _ _ , // _ _ X X X _ _ _ , // _ X _ _ _ X _ _ , // lineNum // _ _ _ _ _ X _ _ , // _ _ _ _ _ X _ _ , // _ _ _ _ X _ _ _ , //_ _ _ X _ _ _ _ , // _ _ X _ _ _ _ _ , // _ X _ _ _ _ _ _ , // _ X X X X X _ _ , // _ _ _ _ _ _ _ _ , // _ _ _ _ _ _ _ _ , // _ _ _ _ _ _ _ _ , // _ _ _ _ _ _ _ _ , void Set_CharWindow(unsigned int lineNum, unsigned int rowNum) { unsigned int x0 = 0; unsigned int y0 = 0; x0 = rowNum<<3; //起始X像素坐标 y0 = lineNum<<4; //其实Y像素坐标 LCD_SetWindow(x0,x0+7,y0,y0+15); } /********************************************************************************************************* ** Function name: LCD_WriteChar ** Descriptions: 向屏幕写一个字节 ** input parameters: lineNum表示字符开始的行数,rowNum表字符开始的列数,共30X20个字符,背景色bkColor,写入的字节chChar 字符颜色----charColor 待显示的字符ch_char ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void LCD_WriteChar(unsigned int lineNum, unsigned int rowNum, unsigned int charColor, unsigned int bkColor, unsigned char chChar) { unsigned char show_cnt = 0; unsigned char bit_cnt = 0; unsigned int charPos = 0; // 字符在字符表中所在的位置 LCD_SELECT(); charPos = Get_CharOffset(chChar); //获取字模显示的偏移量 Set_CharWindow(lineNum, rowNum); //设置起始坐标,xy是8*16的方格坐标 for(show_cnt = 0; show_cnt < 16; show_cnt ++) { for(bit_cnt = 0; bit_cnt < 8; bit_cnt ++) { if( Letter[charPos][show_cnt] & BIT(7 - bit_cnt) ) { LCD_WriteData(charColor); //字符颜色 } else { LCD_WriteData(bkColor); //背景色 } } } LCD_DIS_SELECT(); } /******************************************************************************************************************* ** Function name: LCD_WriteString ** Descriptions: 向屏幕写字符串 ** input parameters: 字符起始行列(lineNum,rowLine),背景色---bkColor,字节颜色---charColor,字符串指针 p_str ** output parameters: 无 ** Returned value: 无 ********************************************************************************************************************/ void LCD_WriteString(unsigned char lineNum, unsigned char rowNum, unsigned int charColor, unsigned int bkColor, unsigned char *p_str) { while(*p_str) { //计算坐标 if(*p_str == '\n') //换行 { rowNum = 0; lineNum++; p_str ++; //调过换行符,不用显示 continue; //查询下一个字符 } else //未遇到换行符则按正常显示坐标自加 { LCD_WriteChar(lineNum,rowNum,charColor,bkColor,*p_str); rowNum++; if(rowNum == CHAR_X_NUM) { rowNum = 0; lineNum ++; if(lineNum == CHAR_Y_NUM) { lineNum = 0; } } } p_str ++; //字符串指针++ } } /********************************************************************************************************* * End Of File * *********************************************************************************************************/
文件名:main.c 主函数测试
/****************************************Copyright (c)************************************************** ** Southeast University **--------------File Info------------------------------------------------------------------------------- ** File Name: main.c ** Last modified Date: 2012-04-11 ** Last Version: 1.0 ** Description: 测试函数 **------------------------------------------------------------------------------------------------------ ** Created By: JianGe ** Created date: 2012-03-23 ** Version: 1.0 **------------------------------------------------------------------------------------------------------ */ # include <iom16v.h> # include <macros.h> # include "Type.h" # include "Delay.h" # include "USART.h" void main(void) { unsigned char* ptr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; USART_Init(); LCD_ILI9325_Init(); LCD_ClearScreen(0xF800); LCD_Fill_Rectangle(0,0,200,200,0xF800); LCD_WriteChar(1,1,0xF800,0xFFFF,'1'); //显示字符 LCD_WriteString(0,0,0xF800,0xFFFF,ptr); //显示字符串 }
posted on 2015-08-26 14:42 jianqi2010 阅读(662) 评论(0) 编辑 收藏 举报