ATmega16L驱动ILI9325/9328

发布者:EtherealEssence最新更新时间:2016-05-03 来源: eefocus关键字:ATmega16L  ILI9325 手机看文章 扫描二维码
随时随地手机看文章
   首先是硬件连线:PB----8位数据口

                                   PA0--- 复位信号RESET

                                   PA1---片选CS

                                   PA2----寄存器选择信号RS

                                   PA3---写信号WR

                                   PA4---读信号RD

 

文件名:Type.h,主要定义一些数据变量的别名

 
  1. /****************************************Copyright (c)**************************************************  
  2. **                                  Southeast University                             
  3. **--------------File Info-------------------------------------------------------------------------------  
  4. ** File Name:          Type.h  
  5. ** Last modified Date: 2012-03-23 
  6. ** Last Version:       1.0  
  7. ** Description:        定义数据类型别名 
  8. **------------------------------------------------------------------------------------------------------  
  9. ** Created By:         JianGe 
  10. ** Created date:       2012-03-23 
  11. ** Version:            1.0  
  12. **------------------------------------------------------------------------------------------------------ */  
  13.    
  14. #ifndef  __TYPE_H__   
  15. #define  __TYPE_H__   
  16.    
  17. /********************************************************************************************************  
  18. *                       Date types(Compiler specific)  数据类型(和编译器相关)                         *                   
  19. ********************************************************************************************************/   
  20. typedef unsigned char  uint8;          // Unsigned  8 bit quantity  无符号8位整型变量  
  21. typedef unsigned char  uchar;          // Unsigned  8 bit quantity  无符号8位整型变量         
  22. typedef signed   char  int8;           // Signed    8 bit quantity  有符号8位整型变量   
  23. typedef unsigned short uint16;         // Unsigned 16 bit quantity  无符号16位整型变量   
  24. typedef signed   short int16;          // Signed   16 bit quantity  有符号16位整型变量    
  25. typedef unsigned int   uint32;         // Unsigned 32 bit quantity  无符号32位整型变量  
  26. typedef unsigned int   uint;         // Unsigned 32 bit quantity  无符号32位整型变量    
  27. typedef signed   int   int32;          // Signed   32 bit quantity  有符号32位整型变量   
  28. typedef float           fp32;          // Single precision floating point 单精度浮点数(32位长度)       
  29. typedef double          fp64;          // Double precision floating point 双精度浮点数(64位长度)     
  30.    
  31. #ifndef TRUE   
  32. #define TRUE  1   
  33. #endif   
  34.    
  35. #ifndef FALSE   
  36. #define FALSE 0   
  37. #endif   
  38.    
  39. #ifndef NULL   
  40. #define NULL  0   
  41. #endif   
  42.    
  43.    
  44.    
  45. #endif   
  46. /*********************************************************************************************************  
  47. *                                        End Of File                                                     *  
  48. *********************************************************************************************************/   

文件名:USART.h,串口操作函数的声明

  1. /****************************************Copyright (c)**************************************************  
  2. **                                  Southeast University                             
  3. **--------------File Info-------------------------------------------------------------------------------  
  4. ** File Name:          USART.h  
  5. ** Last modified Date: 2012-03-23 
  6. ** Last Version:       1.0  
  7. ** Description:        串口函数声明 
  8. **------------------------------------------------------------------------------------------------------  
  9. ** Created By:         JianGe 
  10. ** Created date:       2012-03-23 
  11. ** Version:            1.0  
  12. **------------------------------------------------------------------------------------------------------ */  
  13. #ifndef _USART_H  
  14. #define _USART_H  
  15.   
  16. #include "Type.h"  
  17.   
  18. #define BAUD 9600  //波特率设置  
  19. #define CRYSTAL  4000000  //11059200   //晶振频率   
  20. #define BAUD_SET (uint16)((uint32)CRYSTAL/(16*(uint32)BAUD)-1)  
  21. #define BAUD_H  (uint8)(BAUD_SET>>8)  
  22. #define BAUD_L  (uint8)(BAUD_SET)  
  23.   
  24. #define FE_EER BIT(FE)   //帧接收错误  
  25. #define PE_EER BIT(PE)  //校验错误  
  26. #define DATA_OVER BIT(DOR)  //接收溢出错误  
  27. #define UDR_EMPTY BIT(UDRE) //数据寄存器空  
  28. #define USAT_TX_EN UCSRB|=BIT(TXEN)    //使能USART发送  
  29. #define USAT_TX_NO_EN UCSRB&=~BIT(TXEN)  
  30. #define USAT_RX_EN UCSRB|=BIT(RXEN)    //使能USART接收  
  31. #define USAT_RX_NO_EN UCSRB&=~BIT(RXEN)  
  32.   
  33. extern void USART_Init(void);  
  34. extern void Uart_Transmit(unsigned char i);  
  35. extern unsigned char Uart_Receive( void );  
  36.   
  37. #endif  
  38. /*********************************************************************************************************  
  39. *                                        End Of File                                                     *  
  40. *********************************************************************************************************/   
  41.    

 

文件名:Delay.h,延时函数的声明


 

  1. /****************************************Copyright (c)**************************************************  
  2. **                                  Southeast University                             
  3. **--------------File Info-------------------------------------------------------------------------------  
  4. ** File Name:          Delay.h 
  5. ** Last modified Date: 2012-03-23 
  6. ** Last Version:       1.0  
  7. ** Description:        延时函数声明 
  8. **------------------------------------------------------------------------------------------------------  
  9. ** Created By:         JianGe 
  10. ** Created date:       2012-03-23 
  11. ** Version:            1.0  
  12. **------------------------------------------------------------------------------------------------------ */  
  13. # ifndef DELAY_H_H_  
  14. # define DELAY_H_H_  
  15.   
  16. # define    DELAY_US        asm("nop"); asm("nop"); asm("nop"); asm("nop");\  
  17.                                     asm("nop"); asm("nop"); asm("nop"); asm("nop");  
  18.                                       
  19. extern void Delay_nUS(unsigned int n);  
  20. extern void Delay_MS(void);  
  21. extern void Delay_nMS(unsigned int n);  
  22.   
  23. # endif  
  24.   
  25. /*********************************************************************************************************  
  26. *                                        End Of File                                                     *  
  27. *********************************************************************************************************/   

 


文件名:LCDDriver.h,LCD驱动函数和应用函数的声明

 
  1. /****************************************Copyright (c)**************************************************  
  2. **                                  Southeast University                             
  3. **--------------File Info-------------------------------------------------------------------------------  
  4. ** File Name:          LCD_Driver.h  
  5. ** Last modified Date: 2012-03-24 
  6. ** Last Version:       1.0  
  7. ** Description:        LCD驱动函数声明 
  8. **------------------------------------------------------------------------------------------------------  
  9. ** Created By:         JianGe 
  10. ** Created date:       2012-03-24 
  11. ** Version:            1.0  
  12. **------------------------------------------------------------------------------------------------------ */  
  13. # ifndef LCD_DRIVER_H_H_  
  14. # define LCD_DRIVER_H_H_  
  15.   
  16. # include "Type.h"  
  17. # include   
  18.   
  19.   
  20. extern void LCD_Port_Init(void);  
  21. extern void LCD_WriteCmd(uint32 regID);  
  22. extern void LCD_WriteData(uint32 data);  
  23. extern void LCD_WriteReg(uint32 regID, uint32 regData);  
  24. extern unsigned int LCD_ReadReg(uint32 regID);  
  25. extern void LCD_ILI9325_Init(void);  
  26. extern void LCD_SetWindow(unsigned int x0, unsigned int x1, unsigned int y0, unsigned int y1);  
  27. extern void LCD_ClearScreen(unsigned int color);  
  28. extern void LCD_Fill_Rectangle(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color);  
  29. extern unsigned char Get_CharOffset(unsigned char char_data);  
  30. extern void Set_CharWindow(unsigned int lineNum, unsigned int rowNum);  
  31. extern void LCD_WriteChar(unsigned int lineNum,   
  32.                    unsigned int rowNum,                                                                               
  33.                    unsigned int charColor,                                 
  34.                    unsigned int bkColor,  
  35.                    unsigned char chChar)  
  36. extern void LCD_WriteString(unsigned char lineNum, unsigned char rowNum,  
  37.                      unsigned int charColor,  
  38.                      unsigned int bkColor,  
  39.                      unsigned char *p_str)  
  40.   
  41. # endif  
  42.   
  43. /*********************************************************************************************************  
  44. *                                        End Of File                                                     *  
  45. *********************************************************************************************************/   

文件名:LCD_Font.h  LCD字体库的声明

  1. /****************************************Copyright (c)**************************************************  
  2. **                                  Southeast University                             
  3. **--------------File Info-------------------------------------------------------------------------------  
  4. ** File Name:          LCD_Font.h  
  5. ** Last modified Date: 2012-03-27 
  6. ** Last Version:       1.0  
  7. ** Description:        LCD显示字符的字节表 
  8. **------------------------------------------------------------------------------------------------------  
  9. ** Created By:         JianGe 
  10. ** Created date:       2012-03-27 
  11. ** Version:            1.0  
  12. **------------------------------------------------------------------------------------------------------ */  
  13. # ifndef LCD_FONT_H_H_  
  14. # define LCD_FONT_H_H_  
  15.   
  16. //常用ASCII字符码表                             
  17. const unsigned char Letter[][16] =   
  18. {  
  19. //第一栏从' '到 '?'                        
  20. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/  
  21. {0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x18,0x18,0x00,0x00},/*"!",1*/  
  22. {0x00,0x12,0x36,0x24,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/  
  23. {0x00,0x00,0x00,0x24,0x24,0x24,0xFE,0x48,0x48,0x48,0xFE,0x48,0x48,0x48,0x00,0x00},/*"#",3*/  
  24. {0x00,0x00,0x10,0x38,0x54,0x54,0x50,0x30,0x18,0x14,0x14,0x54,0x54,0x38,0x10,0x10},/*"$",4*/  
  25. {0x00,0x00,0x00,0x44,0xA4,0xA8,0xA8,0xA8,0x54,0x1A,0x2A,0x2A,0x2A,0x44,0x00,0x00},/*"%",5*/  
  26. {0x00,0x00,0x00,0x30,0x48,0x48,0x48,0x50,0x6E,0xA4,0x94,0x88,0x89,0x76,0x00,0x00},/*"&",6*/  
  27. {0x00,0x60,0x60,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/  
  28. {0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00},/*"(",8*/  
  29. {0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00},/*")",9*/  
  30. {0x00,0x00,0x00,0x00,0x10,0x10,0xD6,0x38,0x38,0xD6,0x10,0x10,0x00,0x00,0x00,0x00},/*"*",10*/  
  31. {0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x10,0x00,0x00,0x00},/*"+",11*/  
  32. {0x00,0x60,0x60,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",12*/  
  33. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/  
  34. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00},/*".",14*/  
  35. {0x00,0x00,0x01,0x02,0x02,0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x40,0x00},/*"/",15*/  
  36. {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",16*/  
  37. {0x00,0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"1",17*/  
  38. {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x04,0x04,0x08,0x10,0x20,0x42,0x7E,0x00,0x00},/*"2",18*/  
  39. {0x00,0x00,0x00,0x3C,0x42,0x42,0x04,0x18,0x04,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"3",19*/  
  40. {0x00,0x00,0x00,0x04,0x0C,0x14,0x24,0x24,0x44,0x44,0x7E,0x04,0x04,0x1E,0x00,0x00},/*"4",20*/  
  41. {0x00,0x00,0x00,0x7E,0x40,0x40,0x40,0x58,0x64,0x02,0x02,0x42,0x44,0x38,0x00,0x00},/*"5",21*/  
  42. {0x00,0x00,0x00,0x1C,0x24,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"6",22*/  
  43. {0x00,0x00,0x00,0x7E,0x44,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00},/*"7",23*/  
  44. {0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",24*/  
  45. {0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x26,0x1A,0x02,0x02,0x24,0x38,0x00,0x00},/*"9",25*/  
  46. {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",26*/  
  47. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x20},/*";",27*/  
  48. {0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00},/*"<",28*/  
  49. {0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00},/*"=",29*/  
  50. {0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00},/*">",30*/  
  51. {0x00,0x00,0x00,0x3C,0x42,0x42,0x62,0x02,0x04,0x08,0x08,0x00,0x18,0x18,0x00,0x00},/*"?",31*/  
  52. //第二栏从'@'开始                   
  53. {0x00,0x00,0x00,0x38,0x44,0x5A,0xAA,0xAA,0xAA,0xAA,0xB4,0x42,0x44,0x38,0x00,0x00},/*"@",32*/  
  54. {0x00,0x00,0x00,0x10,0x10,0x18,0x28,0x28,0x24,0x3C,0x44,0x42,0x42,0xE7,0x00,0x00},/*"A",33*/  
  55. {0x00,0x00,0x00,0xF8,0x44,0x44,0x44,0x78,0x44,0x42,0x42,0x42,0x44,0xF8,0x00,0x00},/*"B",34*/  
  56. {0x00,0x00,0x00,0x3E,0x42,0x42,0x80,0x80,0x80,0x80,0x80,0x42,0x44,0x38,0x00,0x00},/*"C",35*/  
  57. {0x00,0x00,0x00,0xF8,0x44,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x44,0xF8,0x00,0x00},/*"D",36*/  
  58. {0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x42,0x42,0xFC,0x00,0x00},/*"E",37*/  
  59. {0x00,0x00,0x00,0xFC,0x42,0x48,0x48,0x78,0x48,0x48,0x40,0x40,0x40,0xE0,0x00,0x00},/*"F",38*/  
  60. {0x00,0x00,0x00,0x3C,0x44,0x44,0x80,0x80,0x80,0x8E,0x84,0x44,0x44,0x38,0x00,0x00},/*"G",39*/  
  61. {0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"H",40*/  
  62. {0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"I",41*/  
  63. {0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x88,0xF0},/*"J",42*/  
  64. {0x00,0x00,0x00,0xEE,0x44,0x48,0x50,0x70,0x50,0x48,0x48,0x44,0x44,0xEE,0x00,0x00},/*"K",43*/  
  65. {0x00,0x00,0x00,0xE0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x42,0xFE,0x00,0x00},/*"L",44*/  
  66. {0x00,0x00,0x00,0xEE,0x6C,0x6C,0x6C,0x6C,0x54,0x54,0x54,0x54,0x54,0xD6,0x00,0x00},/*"M",45*/  
  67. {0x00,0x00,0x00,0xC7,0x62,0x62,0x52,0x52,0x4A,0x4A,0x4A,0x46,0x46,0xE2,0x00,0x00},/*"N",46*/  
  68. {0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x44,0x38,0x00,0x00},/*"O",47*/  
  69. {0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x42,0x7C,0x40,0x40,0x40,0x40,0xE0,0x00,0x00},/*"P",48*/  
  70. {0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82,0x82,0x82,0xB2,0xCA,0x4C,0x38,0x06,0x00},/*"Q",49*/  
  71. {0x00,0x00,0x00,0xFC,0x42,0x42,0x42,0x7C,0x48,0x48,0x44,0x44,0x42,0xE3,0x00,0x00},/*"R",50*/  
  72. {0x00,0x00,0x00,0x3E,0x42,0x42,0x40,0x20,0x18,0x04,0x02,0x42,0x42,0x7C,0x00,0x00},/*"S",51*/  
  73. {0x00,0x00,0x00,0xFE,0x92,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00},/*"T",52*/  
  74. {0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"U",53*/  
  75. {0x00,0x00,0x00,0xE7,0x42,0x42,0x44,0x24,0x24,0x28,0x28,0x18,0x10,0x10,0x00,0x00},/*"V",54*/  
  76. {0x00,0x00,0x00,0xD6,0x92,0x92,0x92,0x92,0xAA,0xAA,0x6C,0x44,0x44,0x44,0x00,0x00},/*"W",55*/  
  77. {0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00},/*"X",56*/  
  78. {0x00,0x00,0x00,0xEE,0x44,0x44,0x28,0x28,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00},/*"Y",57*/  
  79. {0x00,0x00,0x00,0x7E,0x84,0x04,0x08,0x08,0x10,0x20,0x20,0x42,0x42,0xFC,0x00,0x00},/*"Z",58*/  
  80. {0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00},/*"[",59*/  
  81. {0x00,0x00,0x40,0x40,0x20,0x20,0x10,0x10,0x10,0x08,0x08,0x04,0x04,0x04,0x02,0x02},/*"\",60*/  
  82. {0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00},/*"]",61*/  
  83. {0x00,0x1C,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/  
  84. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",63*/  
  85. //第三栏从'''开始                   
  86. {0x00,0x60,0x60,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",64*/  
  87. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x1E,0x22,0x42,0x42,0x3F,0x00,0x00},/*"a",65*/  
  88. {0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x58,0x64,0x42,0x42,0x42,0x64,0x58,0x00,0x00},/*"b",66*/  
  89. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x22,0x40,0x40,0x40,0x22,0x1C,0x00,0x00},/*"c",67*/  
  90. {0x00,0x00,0x00,0x06,0x02,0x02,0x02,0x1E,0x22,0x42,0x42,0x42,0x26,0x1B,0x00,0x00},/*"d",68*/  
  91. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x40,0x40,0x42,0x3C,0x00,0x00},/*"e",69*/  
  92. {0x00,0x00,0x00,0x0F,0x11,0x10,0x10,0x7E,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"f",70*/  
  93. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x44,0x44,0x38,0x40,0x3C,0x42,0x42,0x3C},/*"g",71*/  
  94. {0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x5C,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"h",72*/  
  95. {0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"i",73*/  
  96. {0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x1C,0x04,0x04,0x04,0x04,0x04,0x04,0x44,0x78},/*"j",74*/  
  97. {0x00,0x00,0x00,0xC0,0x40,0x40,0x40,0x4E,0x48,0x50,0x68,0x48,0x44,0xEE,0x00,0x00},/*"k",75*/  
  98. {0x00,0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00},/*"l",76*/  
  99. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x49,0x49,0x49,0x49,0x49,0xED,0x00,0x00},/*"m",77*/  
  100. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,0x62,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"n",78*/  
  101. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"o",79*/  
  102. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD8,0x64,0x42,0x42,0x42,0x44,0x78,0x40,0xE0},/*"p",80*/  
  103. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x22,0x42,0x42,0x42,0x22,0x1E,0x02,0x07},/*"q",81*/  
  104. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEE,0x32,0x20,0x20,0x20,0x20,0xF8,0x00,0x00},/*"r",82*/  
  105. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x42,0x40,0x3C,0x02,0x42,0x7C,0x00,0x00},/*"s",83*/  
  106. {0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x7C,0x10,0x10,0x10,0x10,0x10,0x0C,0x00,0x00},/*"t",84*/  
  107. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC6,0x42,0x42,0x42,0x42,0x46,0x3B,0x00,0x00},/*"u",85*/  
  108. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x10,0x10,0x00,0x00},/*"v",86*/  
  109. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD7,0x92,0x92,0xAA,0xAA,0x44,0x44,0x00,0x00},/*"w",87*/  
  110. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6E,0x24,0x18,0x18,0x18,0x24,0x76,0x00,0x00},/*"x",88*/  
  111. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x28,0x18,0x10,0x10,0xE0},/*"y",89*/  
  112. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x44,0x08,0x10,0x10,0x22,0x7E,0x00,0x00},/*"z",90*/  
  113. {0x00,0x03,0x04,0x04,0x04,0x04,0x04,0x08,0x04,0x04,0x04,0x04,0x04,0x04,0x03,0x00},/*"{",91*/  
  114. {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",92*/  
  115. {0x00,0x60,0x10,0x10,0x10,0x10,0x10,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x60,0x00},/*"}",93*/  
  116. {0x30,0x4C,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/  
  117. {0x00,0x1C,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",95*/  
  118. };  
  119.   
  120. # endif  
  121. /*********************************************************************************************************  
  122. *                                        End Of File                                                     *  
  123. *********************************************************************************************************/  

文件名: Delay.c,延时函数的实现

 

  1. /****************************************Copyright (c)**************************************************  
  2. **                                  Southeast University                             
  3. **--------------File Info-------------------------------------------------------------------------------  
  4. ** File Name:          Delay.c 
  5. ** Last modified Date: 2012-03-23 
  6. ** Last Version:       1.0  
  7. ** Description:        延时函数实现 
  8. **------------------------------------------------------------------------------------------------------  
  9. ** Created By:         JianGe 
  10. ** Created date:       2012-03-23 
  11. ** Version:            1.0  
  12. **------------------------------------------------------------------------------------------------------ */  
  13. #include "Delay.h"  
  14. #include "Type.h"  
  15.   
  16. /*********************************************************************************************************   
  17. ** Function name:       Delay_nUS  
  18. ** Descriptions:        延时n微秒 
  19. ** input parameters:    无 
  20. ** output parameters:   无   
  21. ** Returned value:      无   
  22. *********************************************************************************************************/  
  23. void Delay_nUS(uint32 n)  
  24. {  
  25.     uint32 i=0;  
  26.     for(i=0; i
  27.     {  
  28.         DELAY_US;  
  29.     }  
  30. }  
  31.   
  32. /*********************************************************************************************************   
  33. ** Function name:       Delay_MS  
  34. ** Descriptions:        延时1毫秒 
  35. ** input parameters:    无 
  36. ** output parameters:   无   
  37. ** Returned value:      无   
  38. *********************************************************************************************************/  
  39. void Delay_MS(void)  
  40. {  
  41.     uint32 i=0;  
  42.     for(i=0; i<1000; i++)  
  43.     {  
  44.         DELAY_US;  
  45.     }  
  46. }  
  47.   
  48. /*********************************************************************************************************   
  49. ** Function name:       Delay_nMS 
  50. ** Descriptions:        延时n毫秒 
  51. ** input parameters:    无 
  52. ** output parameters:   无   
  53. ** Returned value:      无   
  54. *********************************************************************************************************/  
  55. void Delay_nMS(uint32 n)  
  56. {  
  57.     uint32 i=0;  
  58.     for(i=0; i
  59.     {  
  60.         Delay_MS();  
  61.     }  
  62. }  
  63.   
  64. /*********************************************************************************************************  
  65. *                                        End Of File                                                     *  
  66. *********************************************************************************************************/   

 

文件名:USART.c 串口调试函数的实现

 

  1. /****************************************Copyright (c)**************************************************  
  2. **                                  Southeast University                             
  3. **--------------File Info-------------------------------------------------------------------------------  
  4. ** File Name:          USART.c 
  5. ** Last modified Date: 2012-03-23 
  6. ** Last Version:       1.0  
  7. ** Description:        串口函数实现 
  8. **------------------------------------------------------------------------------------------------------  
  9. ** Created By:         JianGe 
  10. ** Created date:       2012-03-23 
  11. ** Version:            1.0  
  12. **------------------------------------------------------------------------------------------------------ */  
  13.   
  14. #include   
  15. #include "USART.h"  
  16.   
  17. /*串口初始化函数*/  
  18. void USART_Init(void)   
  19. {   
  20. UCSRA = 0x02;  /*倍速*/   
  21. UCSRB = 0x18;  /*允许接收和发送*/   
  22. UCSRC = 0x06;  /*8位数据*/   
  23. UBRRH = 0x00;   
  24. //UBRRL = 12;  /*9600*/  
  25. //UBRRL = 103;  //11.0592M下9600  
  26. UBRRL = 207;  //16MHz下9600  
  27.   
  28. }/*数据发送,查询方式*/  
  29. void Uart_Transmit(unsigned char i)   
  30. {   
  31.  while (!(UCSRA & (1<
  32.  UDR = i;    /* 发送数据*/  
  33.  }  
  34.  /*数据接收,查询方式*/  
  35.  unsigned char Uart_Receive( void )   
  36.  { while (!(UCSRA & (1<
  37.  return UDR;    /* 获取并返回数据*/  
  38.  }  
  39.   
  40.    
  41.  /*********************************************************************************************************  
  42. *                                        End Of File                                                     *  
  43. *********************************************************************************************************/   

文件名:LCDDriver.c  LCD驱动函数以及上层函数的实现

 

  1. /****************************************Copyright (c)**************************************************  
  2. **                                  Southeast University                             
  3. **--------------File Info-------------------------------------------------------------------------------  
  4. ** File Name:          LCDDriver.c  
  5. ** Last modified Date: 2012-04-12 
  6. ** Last Version:       1.0  
  7. ** Description:        LCD驱动函数的实现 
  8. **------------------------------------------------------------------------------------------------------  
  9. ** Created By:         JianGe 
  10. ** Created date:       2012-03-24 
  11. ** Version:            1.0  
  12. **------------------------------------------------------------------------------------------------------ */  
  13. # include "Delay.h"  
  14. # include   
  15. # include   
  16. # include "USART.h"  
  17. # include "LCD_Font.h"  
  18. # include "Type.h"  
  19.   
  20. ///////////屏显示参数设置///////////////  
  21. //设置屏显示像素大小                   
  22. # define X_SIZE         240  
  23. # define Y_SIZE         320  
  24. //x和y的最大坐标值,坐标原点为(0, 0)       
  25. # define X_END          (X_SIZE - 1)  
  26. # define Y_END          (Y_SIZE - 1)  
  27. //一个字符x*y的分别大小                    
  28. # define CHAR_X_SIZE    8  
  29. # define CHAR_Y_SIZE    16  
  30. //横坐标能显示的字符数X_SIZE/CHAR_X_SIZE  
  31. # define CHAR_X_NUM     30  
  32. //纵坐标能显示的字符数Y_SIZE/CHAR_Y_SIZE  
  33. # define CHAR_Y_NUM     20  
  34. ////////////////////////////////////////  
  35.   
  36.   
  37. //LCD控制端口动作宏定义                        
  38. # define LCD_CS_BIT     PA1   
  39. # define LCD_RS_BIT     PA2   
  40. # define LCD_WR_BIT     PA3   
  41. # define LCD_RD_BIT     PA4    
  42. # define LCD_REST_BIT   PA0   
  43.   
  44. # define LCD_CLT_PORT PORTA  
  45. # define LCD_CLT_PIN  PINA  
  46. # define LCD_CLT_DDR  DDRA  
  47.   
  48.                           
  49. # define LCD_CS_L       LCD_CLT_PORT &= ~BIT(LCD_CS_BIT)  
  50. # define LCD_CS_H       LCD_CLT_PORT |= BIT(LCD_CS_BIT)  
  51.   
  52. # define LCD_RS_L       LCD_CLT_PORT &= ~BIT(LCD_RS_BIT)  
  53. # define LCD_RS_H       LCD_CLT_PORT |= BIT(LCD_RS_BIT)  
  54.   
  55. # define LCD_WR_L       LCD_CLT_PORT &= ~BIT(LCD_WR_BIT)  
  56. # define LCD_WR_H       LCD_CLT_PORT |= BIT(LCD_WR_BIT)  
  57.   
  58. # define LCD_RD_L       LCD_CLT_PORT &= ~BIT(LCD_RD_BIT)  
  59. # define LCD_RD_H       LCD_CLT_PORT |= BIT(LCD_RD_BIT)  
  60.   
  61. # define LCD_REST_L     LCD_CLT_PORT &= ~BIT(LCD_REST_BIT)  
  62. # define LCD_REST_H     LCD_CLT_PORT |= BIT(LCD_REST_BIT)  
  63.   
  64.   
  65. //8位数据口  
  66. # define DATA_H     PB0  
  67. # define LCD_DATA_PORT      PORTB  
  68. # define LCD_DATA_DDR       DDRB  
  69. # define LCD_DATA_PIN       PINB  
  70. # define LCD_DATA_IN        DDRB = 0x00  
  71. # define LCD_DATA_OUT       DDRB = 0xFF  
  72.   
  73.   
  74. //读GRAM时需要一个虚晃的读(Dummy Read)      
  75. # define DUMMY_READ()   LCD_RD_L;LCD_RD_H;LCD_RD_L;LCD_RD_H;  
  76.   
  77. //片选,开始9328的某种操作前调用  
  78. # define LCD_SELECT()  LCD_CS_L  
  79.   
  80. //片选,结束9328的某项操作后调用  
  81. # define LCD_DIS_SELECT() LCD_CS_H  
  82.   
  83.   
  84. /*********************************************************************************************************   
  85. ** Function name:       LCD_Port_Init 
  86. ** Descriptions:        LCD的控制端口和数据端口的初始化 
  87. ** input parameters:    寄存器地址regID 
  88. ** output parameters:   无 
  89. ** Returned value:      无 
  90. *********************************************************************************************************/  
  91.   
  92. void LCD_Port_Init(void)  
  93. {  
  94.     LCD_DATA_OUT;  
  95.     LCD_DATA_PORT = 0xFF;  
  96.     LCD_CLT_DDR = 0xFF;  
  97.     LCD_CS_H;  
  98.     LCD_RS_H;  
  99.     LCD_WR_H;  
  100.     LCD_RD_H;  
  101.     LCD_REST_H;  
  102. }  
  103.   
  104.   
  105. /*********************************************************************************************************   
  106. ** Function name:       LCD_WriteCmd 
  107. ** Descriptions:        写寄存器命令,选择一个寄存器 
  108. ** input parameters:    寄存器地址regID 
  109. ** output parameters:   无 
  110. ** Returned value:      无 
  111. *********************************************************************************************************/  
  112. ///////////////////////////////////////////////////////////////////////////////////////////////////////  
  113.     // nCS       ----\__________________________________________/---------------------------  //  
  114.     // RS        ------\______________________________/------------------------------------  //  
  115.     // nRD       ----------------------------------------------------------------------------  //  
  116.     // nWR       --------\______/----------\_____/-------------------------------------------  //  
  117.     // DB[10:17]  ----[寄存器高8位]-----[寄存器低8位]-------------------------------------------//  
  118. ////////////////////////////////////////////////////////////////////////////////////////////////////////  
  119. void LCD_WriteCmd(uint32 regID)  
  120. {  
  121.     LCD_RS_L;  
  122.       
  123.     LCD_DATA_PORT = regID>>8;  
  124.     LCD_WR_L;  
  125.     LCD_WR_H;  
  126.       
  127.     LCD_DATA_PORT = regID;  
  128.     LCD_WR_L;  
  129.     LCD_WR_H;  
  130.       
  131.     LCD_RS_H;  
  132. }  
  133.   
  134. /*********************************************************************************************************   
  135. ** Function name:       LCD_WriteData 
  136. ** Descriptions:        向LCD写数据 
  137. ** input parameters:    待写入的数据data 
  138. ** output parameters:   无 
  139. ** Returned value:      无 
  140. *********************************************************************************************************/  
  141. ////////////////////////////////////////////////////////////////////////////////////////////////////  
  142.     // nCS       ----\__________________________________________/-----------------------------//  
  143.     // RS        -----------------------------------------------------------------------------//  
  144.     // nRD       -------------------------------------------------------------------------  //  
  145.     // nWR       --------\______/--------\_____/-----------------------------------------  //  
  146.     // DB[10:17]  -----[数据高8位]----- [数据低8位]------------------------------------------- //                                                              
  147. /////////////////////////////////////////////////////////////////////////////////////////////////////  
  148. void LCD_WriteData(uint32 data)  
  149. {  
  150.     LCD_DATA_PORT = data>>8;  
  151.     LCD_WR_L;  
  152.     LCD_WR_H;  
  153.       
  154.     LCD_DATA_PORT = data;  
  155.     LCD_WR_L;  
  156.     LCD_WR_H;  
  157. }  
  158.   
  159.   
  160.   
  161. /*********************************************************************************************************   
  162. ** Function name:       LCD_WriteReg 
  163. ** Descriptions:        向一个寄存器写入数据 
  164. ** input parameters:    寄存器地址:regID 待写入的数据regData 
  165. ** output parameters:   无 
  166. ** Returned value:      无 
  167. *********************************************************************************************************/  
  168. ////////////////////////////////////////////////////////////////////////////////////////////////////  
  169.     // nCS       ----\_____________________________________________________________/--------//  
  170.     // RS        ----\____________________________/-----------------------------------------//  
  171.     // nRD       -------------------------------------------------------------------------  //  
  172.     // nWR       ------\______/--------\_____/--------\______/-----\______/---------------- //  
  173.     // DB[10:17]  ---[寄存器高8位]---[寄存器低8位]---[数据高8位]----[数据低8位]--------------- //                                                              
  174. /////////////////////////////////////////////////////////////////////////////////////////////////////  
  175. void LCD_WriteReg(uint32 regID, uint32 regData)  
  176. {  
  177.     LCD_RS_L;  
  178.       
  179.     LCD_DATA_PORT = regID>>8;  
  180.     LCD_WR_L;  
  181.     LCD_WR_H;  
  182.       
  183.     LCD_DATA_PORT = regID;  
  184.     LCD_WR_L;  
  185.     LCD_WR_H;  
  186.       
  187.     LCD_RS_H;  
  188.     LCD_DATA_PORT = regData>>8;  
  189.     LCD_WR_L;  
  190.     LCD_WR_H;  
  191.       
  192.     LCD_DATA_PORT = regData;  
  193.     LCD_WR_L;  
  194.     LCD_WR_H;  
  195. }  
  196.   
  197.   
  198. /*********************************************************************************************************   
  199. ** Function name:       LCD_ReadReg 
  200. ** Descriptions:        读取指定寄存器的数据 
  201. ** input parameters:    寄存器地址:regID 
  202. ** output parameters:   无 
  203. ** Returned value:      读出数据(16位) 
  204. *********************************************************************************************************/  
  205. ////////////////////////////////////////////////////////////////////////////////////////////////////  
  206.     // nCS       ----\_____________________________________________________________/--------//  
  207.     // RS        ----\____________________________/-----------------------------------------//  
  208.     // nRD       -----------------------------------\_____/------\_____/------------------  //  
  209.     // nWR       ------\______/--------\_____/---------------------------------------------- //  
  210.     // DB[10:17]  ---[寄存器高8位]--[寄存器低8位]--[数据高8位]--[数据低8位]--------------- //                                                              
  211. /////////////////////////////////////////////////////////////////////////////////////////////////////  
  212. unsigned int LCD_ReadReg(uint32 regID)  
  213. {  
  214.     uint32 regData;  
  215.     LCD_WriteCmd(regID);  
  216.       
  217.     LCD_DATA_IN;  
  218.     LCD_RS_H;  
  219.       
  220.     LCD_RD_L;  
  221.     LCD_RD_H;  
  222.     regData = LCD_DATA_PIN;  
  223.       
  224.     regData = regData << 8;  
  225.       
  226.     LCD_RD_L;  
  227.     LCD_RD_H;  
  228.     regData |= LCD_DATA_PIN;  
  229.     LCD_WR_L;  
  230.     LCD_WR_H;  
  231.       
  232.     LCD_DATA_OUT;  
  233.     return regData;  
  234. }  
  235.   
  236.   
  237. /*********************************************************************************************************   
  238. ** Function name:       LCD_ILI9325_Init 
  239. ** Descriptions:        9325/28内部寄存器的初始化 
  240. ** input parameters:    无 
  241. ** output parameters:   无 
  242. ** Returned value:      无 
  243. *********************************************************************************************************/  
  244. void LCD_ILI9325_Init(void)  
  245. {  
  246.     uint32 ID = 0x0000;  
  247.     LCD_Port_Init();  
  248.     LCD_REST_L;  //复位  
  249.     Delay_nMS(50);  
  250.     LCD_REST_H;  
  251.     Delay_nMS(50);  
  252.       
  253.     LCD_SELECT();      
  254.     ID = LCD_ReadReg(0x0000);  // 读LCD的ID,这里是9328  
  255.     Uart_Transmit(ID>>8);  //串口观察  
  256.     Uart_Transmit(ID);  
  257.       
  258.     LCD_WriteReg(0x0001,0x0100);   
  259.     LCD_WriteReg(0x0002,0x0700);   
  260.     LCD_WriteReg(0x0003,0x1030);   //转换RGB至GBR,水平扫描  
  261.     LCD_WriteReg(0x0004,0x0000);   
  262.     LCD_WriteReg(0x0008,0x0207);    
  263.     LCD_WriteReg(0x0009,0x0000);  
  264.     LCD_WriteReg(0x000A,0x0000);   
  265.     LCD_WriteReg(0x000C,0x0000);   
  266.     LCD_WriteReg(0x000D,0x0000);  
  267.     LCD_WriteReg(0x000F,0x0000);  
  268.     //power on sequence VGHVGL  
  269.     LCD_WriteReg(0x0010,0x0000);     
  270.     LCD_WriteReg(0x0011,0x0007);    
  271.     LCD_WriteReg(0x0012,0x0000);    
  272.     LCD_WriteReg(0x0013,0x0000);   
  273.     //vgh   
  274.     LCD_WriteReg(0x0010,0x1290);     
  275.     LCD_WriteReg(0x0011,0x0227);  
  276.     //vregiout   
  277.     LCD_WriteReg(0x0012,0x001d); //0x001b  
  278.     //vom amplitude  
  279.     LCD_WriteReg(0x0013,0x1500);  
  280.     //vom H  
  281.     LCD_WriteReg(0x0029,0x0018);   
  282.     LCD_WriteReg(0x002B,0x000D);   
  283.   
  284.     //gamma  
  285.     LCD_WriteReg(0x0030,0x0004);  
  286.     LCD_WriteReg(0x0031,0x0307);  
  287.     LCD_WriteReg(0x0032,0x0002);// 0006  
  288.     LCD_WriteReg(0x0035,0x0206);  
  289.     LCD_WriteReg(0x0036,0x0408);  
  290.     LCD_WriteReg(0x0037,0x0507);   
  291.     LCD_WriteReg(0x0038,0x0204);//0200  
  292.     LCD_WriteReg(0x0039,0x0707);   
  293.     LCD_WriteReg(0x003C,0x0405);// 0504  
  294.     LCD_WriteReg(0x003D,0x0F02);   
  295.     //ram  
  296.     LCD_WriteReg(0x0050,0x0000);   
  297.     LCD_WriteReg(0x0051,0x00EF);  
  298.     LCD_WriteReg(0x0052,0x0000);   
  299.     LCD_WriteReg(0x0053,0x013F);    
  300.     LCD_WriteReg(0x0060,0xA700);   
  301.     LCD_WriteReg(0x0061,0x0001);   
  302.     LCD_WriteReg(0x006A,0x0000);   
  303.     //  
  304.     LCD_WriteReg(0x0080,0x0000);   
  305.     LCD_WriteReg(0x0081,0x0000);   
  306.     LCD_WriteReg(0x0082,0x0000);   
  307.     LCD_WriteReg(0x0083,0x0000);   
  308.     LCD_WriteReg(0x0084,0x0000);   
  309.     LCD_WriteReg(0x0085,0x0000);   
  310.     //  
  311.     LCD_WriteReg(0x0090,0x0010);   
  312.     LCD_WriteReg(0x0092,0x0600);   
  313.     LCD_WriteReg(0x0093,0x0003);   
  314.     LCD_WriteReg(0x0095,0x0110);   
  315.     LCD_WriteReg(0x0097,0x0000);   
  316.     LCD_WriteReg(0x0098,0x0000);  
  317.     LCD_WriteReg(0x0007,0x0133);  
  318.     LCD_DIS_SELECT();  
  319. }  
  320.   
  321.       
  322. /*********************************************************************************************************   
  323. ** Function name:       LCD_SetWindow 
  324. ** Descriptions:        定义刷屏窗口 
  325. ** input parameters:    起始坐标 (x0,y0),终止坐标(x1,y1) 
  326. ** output parameters:   无 
  327. ** Returned value:      无 
  328. *********************************************************************************************************/  
  329. static void LCD_SetWindow(unsigned int x0, unsigned int x1, unsigned int y0, unsigned int y1)  
  330. {  
  331.     LCD_WriteReg(0x0050,x0);  
  332.     LCD_WriteReg(0x0051,x1);  
  333.     LCD_WriteReg(0x0052,y0);  
  334.     LCD_WriteReg(0x0053,y1);  
  335.     LCD_WriteReg(0x0020,x0);  
  336.     LCD_WriteReg(0x0021,y0);  
  337.     LCD_WriteCmd(0x0022);   //GRAM寄存器,之后可以写GRAM缓冲区  
  338. }  
  339.   
  340.   
  341.   
  342.   
  343.   
  344. /*******************************************************************************************************************/  
  345. /*******************************************************************************************************************/  
  346. /**************************************************以下为LCD的应用函数**********************************************/  
  347. /*******************************************************************************************************************/  
  348. /*******************************************************************************************************************/  
  349.   
  350.   
  351. /*********************************************************************************************************   
  352. ** Function name:       LCD_ClearScreen 
  353. ** Descriptions:        刷整屏为一种颜色 
  354. ** input parameters:    颜色的RGB值color 
  355. ** output parameters:   无 
  356. ** Returned value:      无 
  357. *********************************************************************************************************/  
  358. void LCD_ClearScreen(unsigned int color)  
  359. {  
  360.         unsigned int i,j;  
  361.         LCD_SELECT();   //选择9328  
  362.         LCD_SetWindow(0,240,0,320); //320x240的屏  
  363.         for (i=0;i<320;i++)  
  364.         {  
  365.             for (j=0;j<240;j++)  
  366.             {  
  367.                 LCD_WriteData(color); //向GRAM写入RGB数据  
  368.             }  
  369.         }  
  370.         LCD_DIS_SELECT(); //操作完毕  
  371. }  
  372.   
  373. /*********************************************************************************************************   
  374. ** Function name:       LCD_Fill 
  375. ** Descriptions:        填充一个矩形区域     
  376. ** input parameters:    矩形起始坐标----(x0,y0),矩形终点坐标--(x1,y1) 
  377. ** output parameters:   无 
  378. ** Returned value:      无 
  379. *********************************************************************************************************/    
  380. //                    
  381. void LCD_Fill_Rectangle(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color)  
  382. {  
  383.     unsigned long  i;  
  384.       
  385.     LCD_SELECT();   //选择9328  
  386.     LCD_SetWindow(x0, x1, y0, y1);  
  387.       
  388.     for(i=0; i < (x1 - x0 + 1)*(y1 - y0 + 1); i++)                 
  389.     {  
  390.         LCD_WriteData(color);       //填充颜色                                
  391.     }  
  392.       
  393.     LCD_DIS_SELECT(); //操作完毕                      
  394. }  
  395.   
  396.   
  397. /*********************************************************************************************************   
  398. ** Function name:       Get_CharOffset 
  399. ** Descriptions:        获取字节的偏移量  
  400. ** input parameters:    输入字节 
  401. ** output parameters:   无 
  402. ** Returned value:      偏移量 
  403. *********************************************************************************************************/  
  404. unsigned char Get_CharOffset(unsigned char char_data)  
  405. {  
  406.     if(char_data >= ' ' && char_data <= '}')  
  407.     {  
  408.         char_data -= ' ';                       //字符偏移从空格开始               
  409.     }  
  410.     else   
  411.     {  
  412.         char_data = ' ';                        //如无匹配字符以空格代替             
  413.     }  
  414.     return char_data;   //返回字符所在字符表的位置  
  415. }  
  416.   
  417.   
  418. /*********************************************************************************************************   
  419. ** Function name:       Set_CharWindow 
  420. ** Descriptions:        设置字节窗口 
  421. ** input parameters:    每个字符8X16像素,共30行20列,lineNum----字符所在行号,rowLine----字符所在列号 
  422. ** output parameters:   无 
  423. ** Returned value:      无 
  424. *********************************************************************************************************/  
  425. //例如显示'2'这个字节窗口,为一个8X16的像素矩形  
  426. // _ _ _ _ _ _ _ _ ,  
  427. // _ _ _ _ _ _ _ _ ,  
  428. // _ _ _ _ _ _ _ _ ,  
  429. // _ _ X X X _ _ _ ,  
  430. // _ X _ _ _ X _ _ ,        // lineNum  
  431. // _ _ _ _ _ X _ _ ,  
  432. // _ _ _ _ _ X _ _ ,  
  433. // _ _ _ _ X _ _ _ ,  
  434. //_ _ _ X _ _ _ _ ,  
  435. // _ _ X _ _ _ _ _ ,  
  436. // _ X _ _ _ _ _ _ ,  
  437. // _ X X X X X _ _ ,  
  438. // _ _ _ _ _ _ _ _ ,  
  439. // _ _ _ _ _ _ _ _ ,  
  440. // _ _ _ _ _ _ _ _ ,  
  441. // _ _ _ _ _ _ _ _ ,  
  442.   
  443. void Set_CharWindow(unsigned int lineNum, unsigned int rowNum)  
  444. {  
  445.     unsigned int x0 = 0;   
  446.     unsigned int y0 = 0;  
  447.       
  448.     x0 = rowNum<<3;   //起始X像素坐标     
  449.     y0 = lineNum<<4;   //其实Y像素坐标  
  450.       
  451.     LCD_SetWindow(x0,x0+7,y0,y0+15);  
  452. }  
  453.   
  454. /*********************************************************************************************************   
  455. ** Function name:     LCD_WriteChar 
  456. ** Descriptions:      向屏幕写一个字节 
  457. ** input parameters:   lineNum表示字符开始的行数,rowNum表字符开始的列数,共30X20个字符,背景色bkColor,写入的字节chChar 
  458.                        字符颜色----charColor 
  459.                        待显示的字符ch_char 
  460. ** output parameters:  无 
  461. ** Returned value:     无 
  462. *********************************************************************************************************/  
  463. void LCD_WriteChar(unsigned int lineNum,   
  464.                    unsigned int rowNum,                                                                               
  465.                    unsigned int charColor,                                 
  466.                    unsigned int bkColor,  
  467.                    unsigned char chChar)  
  468. {  
  469.     unsigned char show_cnt = 0;  
  470.     unsigned char bit_cnt = 0;  
  471.     unsigned int charPos = 0; // 字符在字符表中所在的位置  
  472.       
  473.     LCD_SELECT();   
  474.     charPos = Get_CharOffset(chChar);       //获取字模显示的偏移量                  
  475.     Set_CharWindow(lineNum, rowNum);        //设置起始坐标,xy是8*16的方格坐标     
  476.       
  477.     for(show_cnt = 0; show_cnt < 16; show_cnt ++)  
  478.     {                                                 
  479.                                                       
  480.         for(bit_cnt = 0; bit_cnt < 8; bit_cnt ++)  
  481.         {  
  482.             if( Letter[charPos][show_cnt] & BIT(7 - bit_cnt) )  
  483.             {  
  484.                 LCD_WriteData(charColor);  //字符颜色  
  485.             }  
  486.             else  
  487.             {  
  488.                 LCD_WriteData(bkColor);  //背景色  
  489.             }  
  490.         }  
  491.     }  
  492.     LCD_DIS_SELECT();             
  493. }  
  494.   
  495.   
  496. /*******************************************************************************************************************   
  497. ** Function name:       LCD_WriteString 
  498. ** Descriptions:        向屏幕写字符串 
  499. ** input parameters:    字符起始行列(lineNum,rowLine),背景色---bkColor,字节颜色---charColor,字符串指针 p_str 
  500. ** output parameters:   无 
  501. ** Returned value:      无 
  502. ********************************************************************************************************************/  
  503. void LCD_WriteString(unsigned char lineNum, unsigned char rowNum,  
  504.                      unsigned int charColor,  
  505.                      unsigned int bkColor,  
  506.                      unsigned char *p_str)  
  507. {  
  508.     while(*p_str)  
  509.     {  
  510.         //计算坐标                            
  511.         if(*p_str == '\n')                  //换行                                  
  512.         {  
  513.             rowNum = 0;  
  514.             lineNum++;  
  515.             p_str ++;                       //调过换行符,不用显示                  
  516.             continue;                       //查询下一个字符                     
  517.         }  
  518.         else                                //未遇到换行符则按正常显示坐标自加    
  519.         {  
  520.             LCD_WriteChar(lineNum,rowNum,charColor,bkColor,*p_str);  
  521.             rowNum++;  
  522.             if(rowNum == CHAR_X_NUM)  
  523.             {  
  524.                 rowNum = 0;  
  525.                 lineNum ++;  
  526.                 if(lineNum == CHAR_Y_NUM)  
  527.                 {  
  528.                     lineNum = 0;  
  529.                 }  
  530.             }  
  531.         }             
  532.         p_str ++;  //字符串指针++  
  533.     }  
  534. }  
  535.   
  536. /*********************************************************************************************************  
  537. *                                        End Of File                                                     *  
  538. *********************************************************************************************************/  

 

文件名:main.c 主函数测试

  1. /****************************************Copyright (c)**************************************************  
  2. **                                  Southeast University                             
  3. **--------------File Info-------------------------------------------------------------------------------  
  4. ** File Name:          main.c  
  5. ** Last modified Date: 2012-04-11 
  6. ** Last Version:       1.0  
  7. ** Description:        测试函数 
  8. **------------------------------------------------------------------------------------------------------  
  9. ** Created By:         JianGe 
  10. ** Created date:       2012-03-23 
  11. ** Version:            1.0  
  12. **------------------------------------------------------------------------------------------------------ */  
  13.   
  14.   
  15. # include   
  16. # include   
  17. # include "Type.h"  
  18. # include "Delay.h"  
  19. # include "USART.h"  
  20.   
  21. void main(void)  
  22. {  
  23.     unsigned char* ptr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";  
  24.     USART_Init();   
  25.     LCD_ILI9325_Init();  
  26.     LCD_ClearScreen(0xF800);    
  27.     LCD_Fill_Rectangle(0,0,200,200,0xF800);   
  28.     LCD_WriteChar(1,1,0xF800,0xFFFF,'1');  //显示字符  
  29.     LCD_WriteString(0,0,0xF800,0xFFFF,ptr);  //显示字符串  
  30. }  

关键字:ATmega16L  ILI9325 引用地址:ATmega16L驱动ILI9325/9328

上一篇:AVR的中断问题
下一篇:AVR串口(USART)基本操作函数

推荐阅读最新更新时间:2024-03-16 14:52

基于Atmega16L的高精度频率调节器
1 引言 在现代化工业生产与高精度测试中,我们需要相当精确的频率来帮助判断设备性能指标。而且我们希望能够微调该频率。采用压控振荡器得到的频率不够精确,微调频率步骤烦琐,耗时漫长,因此有些测试项目限制了压控振荡器的使用。 Mega系列单片机是Atmel公司于2002年起陆续推出的。这款AVR增强型单片机具有速度快,抗干扰能力强,价格低廉等诸多优点。为了加快AVR单片机的软件编制,Atmel以及第三方提供的开发工具多种多样,程序开发方便有效。该单片机内部FLASH结构功能灵活,加锁后很难解密,可以最大限度地保护知识产权。AVR单片机可以广泛应用于通信、野外测试、汽车电子、医疗器械等领域,并且适用于各种低电压、低功耗的场合。 本
[单片机]
基于<font color='red'>Atmega16L</font>的高精度频率调节器
基于MC9328MX1嵌入式最小系统的设计
引言 嵌入式系统是以实际应用为核心,对功能、可靠性、成本、体积、功耗有严格要求的专业计算机系统,随着嵌入式系统相关技术的迅速发展,嵌入式系统功能越来越 强,应用接口更加丰富,根据实际应用的需要设计出特定的嵌入式最小系统和应用系统,是嵌入式系统设计人员应具备的能力,由于ARM嵌入式体系的结构的一致 性以及外围电路的通用性,采用ARM内核的嵌入式最小系统的设计原则和设计方法基本相同,本文基于MC9328MX1芯片介绍ARM嵌入式最小系统设计的 一般方法。 1 MC9328MX1概述 MC9328MX1是Motorola公司基于ARM920T的龙珠(Dragon Ball)MX1处理器,MC9328MX1内含ARM公司
[单片机]
用AVR单片机实现多功能数显电子秤的设计方案
简介:本方案设计采用AVR系列单片机ATMEGA16L作为微控制器,结合压力传感器、模数转换芯片AD7705、液晶模块LCD1602实现的一种高精度多功能数显电子秤,具有体积小、成本低、精确度高、可靠性高等优点。文章详细介绍了系统的硬件电路结构和软件的程序开发流程。 本方案设计采用AVR系列单片机ATMEGA16L作为微控制器,结合压力传感器、模数转换芯片AD7705、液晶模块LCD1602实现的一种高精度多功能数显电子秤,具有体积小、成本低、精确度高、可靠性高等优点。文章详细介绍了系统的硬件电路结构和软件的程序开发流程。 一、引言 随着电子技术和自动化测量技术的不断发展,传统的称重系统在功能、精度、性价比等方面已难以
[单片机]
用AVR单片机实现多功能数显电子秤的设计方案
ATmega16L-EEPROM写入读取实验
/*************************************** 读写AVR单片机EEPROM实验。 先向单片机EEPROM写入1到255,然后依次读出, 并在数码管上显示出来 ***************************************/ #include iom16v.h const unsigned char duanma ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; const unsigned char weima ={0xfe,0xfd
[单片机]
小广播
添点儿料...
无论热点新闻、行业分析、技术干货……
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved