S3C2440-AD应用

S3C2440-AD应用

哈尔滨理工大学软件工程专业08-7李万鹏原创作品,转载请标明出处

http://blog.csdn.net/woshixingaaa/archive/2010/12/19/6085783.aspx

使用电位器模拟传感器,进行模数转化,将AD值转化为温度值,实时显示在LCD上。汉字使用48*48字模,字符使用24*48字模。通过软件PCtoLCD2002提取字模。这里主要用到ADCCON寄存器。首先要使能预分频器,因为太快会没转化完,所以降低频率,设置分频比,然后是选择模拟输入通道。然后启动AD转换,该位在开始后自动清零,通过ECFLG位检查是否转化结束。ADCDAT0低10位用来存放转化来的数据。

S3C2440-AD应用_第1张图片

C-sharp代码
  1. #include "2440addr.h"      
  2. //垂直同步信号的脉宽、后肩和前肩        
  3. #define VSPW       15        
  4. #define VBPD       3        
  5. #define VFPD       5         
  6. //水平同步信号的脉宽、后肩和前肩        
  7. #define HSPW       8        
  8. #define HBPD       58        
  9. #define HFPD      15        
  10. #define CLKVAL 10        
  11. #define HOZVAL 319        
  12. #define LINEVAL 239        
  13. #define PWREN 1        
  14. #define MMODE 0        
  15. #define PNRMODE 3        
  16. #define BPPMODE 13        
  17. #define INVVCLK 0        
  18. #define INVVD 0        
  19. #define INVVDEN 0         
  20. #define U32 unsigned int         
  21. #define M5D(n) ((n) & 0x1fffff)        
  22. #define PAGEWIDTH 320        
  23. #define OFFSIZE 0        
  24. #define LCD_XSIZE 320        
  25. #define LCD_YSIZE 240        
  26. #define SCR_XSIZE 320        
  27. #define SCR_YSIZE 240        
  28. #define INVVLINE  1            
  29. #define INVVFRAME 1             
  30. #define BPP24BL 0        
  31. #define BSWP 0        
  32. #define HWSWP 0         
  33. volatile U32 LCD_BUFFER[240][320];         
  34.         
  35. //48*48      
  36. unsigned char wen[] = {                                                              //温      
  37. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  38. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x20,0x00,0x0C,0x00,0x01,0x80,      
  39. 0x38,0x00,0x1E,0x00,0x01,0xE0,0x3F,0xFF,0xFF,0x00,0x00,0xE0,0x38,0x00,0x0C,0x00,      
  40. 0x00,0xF0,0x38,0x00,0x0C,0x00,0x00,0x70,0x38,0x00,0x0C,0x00,0x00,0x70,0xB8,0x00,      
  41. 0x0C,0x00,0x00,0x21,0x38,0x00,0x0C,0x00,0x00,0x01,0x38,0x00,0x0C,0x00,0x00,0x01,      
  42. 0x3F,0xFF,0xFC,0x00,0x00,0x02,0x38,0x00,0x0C,0x00,0x30,0x02,0x38,0x00,0x0C,0x00,      
  43. 0x1C,0x06,0x38,0x00,0x0C,0x00,0x0E,0x04,0x38,0x00,0x0C,0x00,0x0F,0x04,0x38,0x00,      
  44. 0x0C,0x00,0x07,0x08,0x38,0x00,0x0C,0x00,0x07,0x08,0x38,0x00,0x0C,0x00,0x03,0x18,      
  45. 0x3F,0xFF,0xFC,0x00,0x03,0x10,0x38,0x00,0x0C,0x00,0x00,0x30,0x38,0x00,0x0C,0x00,      
  46. 0x00,0x30,0x20,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x61,0x80,0x00,      
  47. 0x01,0x80,0x00,0x61,0xFF,0xFF,0xFF,0xC0,0x00,0xC1,0xC1,0x81,0x83,0xC0,0x00,0xC1,      
  48. 0xC1,0x81,0x83,0x80,0x01,0xC1,0xC1,0x81,0x83,0x80,0x43,0x81,0xC1,0x81,0x83,0x80,      
  49. 0x3F,0x81,0xC1,0x81,0x83,0x80,0x07,0x81,0xC1,0x81,0x83,0x80,0x03,0x01,0xC1,0x81,      
  50. 0x83,0x80,0x03,0x01,0xC1,0x81,0x83,0x80,0x03,0x01,0xC1,0x81,0x83,0x80,0x03,0x01,      
  51. 0xC1,0x81,0x83,0x80,0x07,0x01,0xC1,0x81,0x83,0x80,0x07,0x01,0xC1,0x81,0x83,0x80,      
  52. 0x07,0x01,0xC1,0x81,0x83,0x90,0x07,0x01,0xC1,0x81,0x83,0xB8,0x07,0x81,0xC1,0x81,      
  53. 0x83,0xBC,0x01,0x7E,0x3E,0x7E,0x7C,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  54. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};       
  55.        
  56. unsigned char du[] = {                                                               //度      
  57. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,      
  58. 0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,      
  59. 0x00,0xF0,0x00,0x00,0x01,0x00,0x00,0x70,0x00,0x40,0x01,0x80,0x00,0x60,0x00,0xE0,      
  60. 0x01,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0xC0,0x10,0x00,      
  61. 0x80,0x00,0x00,0xC0,0x1C,0x00,0xE0,0x00,0x00,0xC0,0x1E,0x00,0xF0,0x00,0x00,0xC0,      
  62. 0x1C,0x00,0xE0,0x00,0x00,0xC0,0x1C,0x00,0xE0,0x40,0x00,0xC0,0x1C,0x00,0xE0,0xE0,      
  63. 0x00,0xDF,0xFF,0xFF,0xFF,0xF0,0x00,0xC8,0x1C,0x00,0xE0,0x00,0x00,0xC0,0x1C,0x00,      
  64. 0xE0,0x00,0x01,0xC0,0x1C,0x00,0xE0,0x00,0x01,0xC0,0x1C,0x00,0xE0,0x00,0x01,0xC0,      
  65. 0x1C,0x00,0xE0,0x00,0x01,0xC0,0x1C,0x00,0xE0,0x00,0x01,0xC0,0x1F,0xFF,0xE0,0x00,      
  66. 0x01,0xC0,0x1C,0x00,0xE0,0x00,0x01,0xC0,0x10,0x00,0x80,0x00,0x01,0xC0,0x00,0x00,      
  67. 0x10,0x00,0x01,0x80,0x00,0x00,0x38,0x00,0x01,0x81,0xFF,0xFF,0xFC,0x00,0x01,0x80,      
  68. 0x08,0x00,0x78,0x00,0x01,0x80,0x0C,0x00,0x70,0x00,0x03,0x80,0x06,0x00,0xE0,0x00,      
  69. 0x03,0x00,0x03,0x01,0xC0,0x00,0x03,0x00,0x03,0x03,0xC0,0x00,0x03,0x00,0x01,0x87,      
  70. 0x80,0x00,0x03,0x00,0x00,0xCF,0x00,0x00,0x06,0x00,0x00,0x7E,0x00,0x00,0x06,0x00,      
  71. 0x00,0x3C,0x00,0x00,0x06,0x00,0x00,0x7C,0x00,0x00,0x0C,0x00,0x01,0xFF,0x00,0x00,      
  72. 0x0C,0x00,0x03,0xC7,0xE0,0x00,0x08,0x00,0x0F,0x01,0xFE,0x00,0x18,0x00,0x78,0x00,      
  73. 0x7F,0xF8,0x10,0x03,0xE0,0x00,0x1F,0xE0,0x20,0x1E,0x00,0x00,0x03,0xC0,0x20,0xE0,      
  74. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};      
  75. unsigned char s1[] = {                                                               //:      
  76. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  77. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  78. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  79. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  80. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  81. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  82. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  83. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  84. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  85. 0x00,0xE0,0x00,0x00,0x00,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x03,0xF8,0x00,0x00,      
  86. 0x00,0x00,0x03,0xF8,0x00,0x00,0x00,0x00,0x03,0xF8,0x00,0x00,0x00,0x00,0x01,0xF0,      
  87. 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  88. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  89. 0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x03,0xF8,      
  90. 0x00,0x00,0x00,0x00,0x03,0xF8,0x00,0x00,0x00,0x00,0x03,0xF8,0x00,0x00,0x00,0x00,      
  91. 0x01,0xF0,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  92. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  93. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};      
  94. unsigned char s2[] = {                                                               //℃      
  95. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  96. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  97. 0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x98,0x00,0xFF,0x80,0x00,      
  98. 0x03,0x0C,0x03,0xFF,0xE0,0x00,0x02,0x0C,0x0F,0x80,0x38,0x80,0x02,0x0C,0x1E,0x00,      
  99. 0x0C,0x80,0x03,0x0C,0x3C,0x00,0x06,0x80,0x03,0x18,0x38,0x00,0x03,0x80,0x01,0xF8,      
  100. 0x70,0x00,0x01,0x80,0x00,0x00,0xF0,0x00,0x01,0x80,0x00,0x00,0xE0,0x00,0x01,0x80,      
  101. 0x00,0x01,0xE0,0x00,0x00,0x80,0x00,0x01,0xC0,0x00,0x00,0x80,0x00,0x01,0xC0,0x00,      
  102. 0x00,0x80,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x03,      
  103. 0xC0,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,      
  104. 0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,      
  105. 0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x01,      
  106. 0xC0,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,      
  107. 0x00,0x00,0xE0,0x00,0x00,0x80,0x00,0x00,0xF0,0x00,0x01,0x80,0x00,0x00,0x78,0x00,      
  108. 0x01,0x00,0x00,0x00,0x38,0x00,0x02,0x00,0x00,0x00,0x3C,0x00,0x0E,0x00,0x00,0x00,      
  109. 0x1F,0x00,0x38,0x00,0x00,0x00,0x0F,0xE1,0xF0,0x00,0x00,0x00,0x03,0xFF,0xC0,0x00,      
  110. 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  111. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  112. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};      
  113. //24*48      
  114. unsigned char num[] = {      
  115. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                             //0      
  116. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  117. 0x00,0x00,0x0F,0xFF,0xF8,0x0F,0xFF,0xF8,0x0F,0xFF,0xF0,      
  118. 0x0E,0x00,0x30,0x08,0x00,0x60,0x18,0x00,0x40,0x10,0x00,      
  119. 0xC0,0x10,0x00,0x80,0x00,0x01,0x80,0x00,0x01,0x00,0x00,      
  120. 0x03,0x00,0x00,0x02,0x00,0x00,0x06,0x00,0x00,0x04,0x00,      
  121. 0x00,0x0C,0x00,0x00,0x0C,0x00,0x00,0x18,0x00,0x00,0x18,      
  122. 0x00,0x00,0x38,0x00,0x00,0x30,0x00,0x00,0x30,0x00,0x00,      
  123. 0x70,0x00,0x00,0x70,0x00,0x00,0x70,0x00,0x00,0x70,0x00,      
  124. 0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,      
  125. 0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0x70,0x00,0x00,      
  126. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  127. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  128. 0x00,      
  129. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                              //1      
  130. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  131. 0x00,0x00,0x00,0x04,0x00,0x00,0x0C,0x00,0x00,0x1C,0x00,      
  132. 0x03,0xFC,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,      
  133. 0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,      
  134. 0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,      
  135. 0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,      
  136. 0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,      
  137. 0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,      
  138. 0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,0x00,0x00,0x1C,      
  139. 0x00,0x00,0x1C,0x00,0x00,0x3E,0x00,0x03,0xFF,0xE0,0x00,      
  140. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  141. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  142. 0x00,      
  143. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                              //2      
  144. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  145. 0x00,0x00,0x00,0x7E,0x00,0x01,0x83,0x80,0x06,0x01,0xC0,      
  146. 0x0C,0x00,0xE0,0x0C,0x00,0xE0,0x1C,0x00,0x70,0x1C,0x00,      
  147. 0x70,0x1C,0x00,0x70,0x1E,0x00,0x70,0x1E,0x00,0x70,0x0E,      
  148. 0x00,0x70,0x00,0x00,0xE0,0x00,0x00,0xE0,0x00,0x01,0xC0,      
  149. 0x00,0x01,0xC0,0x00,0x03,0x80,0x00,0x07,0x00,0x00,0x0E,      
  150. 0x00,0x00,0x1C,0x00,0x00,0x38,0x00,0x00,0x70,0x00,0x00,      
  151. 0xE0,0x00,0x01,0xC0,0x00,0x01,0x80,0x00,0x03,0x00,0x10,      
  152. 0x06,0x00,0x10,0x0C,0x00,0x30,0x18,0x00,0x30,0x10,0x00,      
  153. 0x60,0x3F,0xFF,0xE0,0x3F,0xFF,0xE0,0x3F,0xFF,0xE0,0x00,      
  154. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  155. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  156. 0x00,      
  157. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                              //3      
  158. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  159. 0x00,0x00,0x00,0x7E,0x00,0x01,0x83,0x80,0x03,0x01,0xC0,      
  160. 0x06,0x00,0xE0,0x0E,0x00,0xE0,0x0E,0x00,0x70,0x0F,0x00,      
  161. 0x70,0x0F,0x00,0x70,0x07,0x00,0x70,0x00,0x00,0x70,0x00,      
  162. 0x00,0x60,0x00,0x00,0xE0,0x00,0x00,0xC0,0x00,0x01,0x80,      
  163. 0x00,0x07,0x00,0x00,0x7C,0x00,0x00,0x07,0x80,0x00,0x00,      
  164. 0xC0,0x00,0x00,0x60,0x00,0x00,0x70,0x00,0x00,0x30,0x00,      
  165. 0x00,0x38,0x00,0x00,0x38,0x0C,0x00,0x38,0x1E,0x00,0x38,      
  166. 0x1E,0x00,0x38,0x1E,0x00,0x30,0x1C,0x00,0x70,0x0C,0x00,      
  167. 0x60,0x06,0x00,0xC0,0x03,0x03,0x80,0x00,0xFE,0x00,0x00,      
  168. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  169. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  170. 0x00,      
  171. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                             //4      
  172. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  173. 0x00,0x00,0x00,0x01,0x80,0x00,0x03,0x80,0x00,0x03,0x80,      
  174. 0x00,0x07,0x80,0x00,0x0F,0x80,0x00,0x0B,0x80,0x00,0x1B,      
  175. 0x80,0x00,0x13,0x80,0x00,0x33,0x80,0x00,0x63,0x80,0x00,      
  176. 0x43,0x80,0x00,0xC3,0x80,0x01,0x83,0x80,0x01,0x03,0x80,      
  177. 0x03,0x03,0x80,0x02,0x03,0x80,0x04,0x03,0x80,0x0C,0x03,      
  178. 0x80,0x08,0x03,0x80,0x18,0x03,0x80,0x30,0x03,0x80,0x3F,      
  179. 0xFF,0xFC,0x3F,0xFF,0xFC,0x00,0x03,0x80,0x00,0x03,0x80,      
  180. 0x00,0x03,0x80,0x00,0x03,0x80,0x00,0x03,0x80,0x00,0x03,      
  181. 0x80,0x00,0x03,0x80,0x00,0x03,0xC0,0x00,0x7F,0xFC,0x00,      
  182. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  183. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  184. 0x00,      
  185. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                          //5      
  186. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  187. 0x00,0x00,0x07,0xFF,0xF0,0x07,0xFF,0xF0,0x07,0xFF,0xF0,      
  188. 0x04,0x00,0x00,0x04,0x00,0x00,0x04,0x00,0x00,0x04,0x00,      
  189. 0x00,0x04,0x00,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,      
  190. 0x00,0x00,0x08,0x7F,0x00,0x09,0xFF,0x80,0x0B,0x81,0xC0,      
  191. 0x0E,0x00,0xE0,0x0E,0x00,0x70,0x0C,0x00,0x70,0x00,0x00,      
  192. 0x78,0x00,0x00,0x38,0x00,0x00,0x38,0x00,0x00,0x38,0x00,      
  193. 0x00,0x38,0x0C,0x00,0x38,0x1E,0x00,0x38,0x1E,0x00,0x38,      
  194. 0x1E,0x00,0x30,0x1C,0x00,0x70,0x0C,0x00,0x70,0x0C,0x00,      
  195. 0xE0,0x06,0x00,0xC0,0x03,0x83,0x80,0x00,0xFE,0x00,0x00,      
  196. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  197. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  198. 0x00,      
  199. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                            //6      
  200. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  201. 0x00,0x00,0x00,0x3F,0x00,0x00,0xC1,0xC0,0x01,0x81,0xC0,      
  202. 0x03,0x01,0xE0,0x06,0x01,0xE0,0x0C,0x01,0xE0,0x0C,0x00,      
  203. 0x00,0x0C,0x00,0x00,0x1C,0x00,0x00,0x18,0x00,0x00,0x18,      
  204. 0x00,0x00,0x38,0x00,0x00,0x38,0x3F,0x00,0x38,0xFF,0xC0,      
  205. 0x3B,0xC1,0xE0,0x3B,0x00,0xE0,0x3E,0x00,0x70,0x3C,0x00,      
  206. 0x70,0x38,0x00,0x38,0x38,0x00,0x38,0x38,0x00,0x38,0x38,      
  207. 0x00,0x38,0x38,0x00,0x38,0x18,0x00,0x38,0x1C,0x00,0x38,      
  208. 0x1C,0x00,0x38,0x0C,0x00,0x30,0x0E,0x00,0x70,0x06,0x00,      
  209. 0x60,0x03,0x00,0xC0,0x01,0xC1,0x80,0x00,0x7E,0x00,0x00,      
  210. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  211. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  212. 0x00,      
  213. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                             //7      
  214. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  215. 0x00,0x00,0x0F,0xFF,0xF8,0x0F,0xFF,0xF8,0x0F,0xFF,0xF0,      
  216. 0x0E,0x00,0x30,0x08,0x00,0x60,0x18,0x00,0x40,0x10,0x00,      
  217. 0xC0,0x10,0x00,0x80,0x00,0x01,0x80,0x00,0x01,0x00,0x00,      
  218. 0x03,0x00,0x00,0x02,0x00,0x00,0x06,0x00,0x00,0x04,0x00,      
  219. 0x00,0x0C,0x00,0x00,0x0C,0x00,0x00,0x18,0x00,0x00,0x18,      
  220. 0x00,0x00,0x38,0x00,0x00,0x30,0x00,0x00,0x30,0x00,0x00,      
  221. 0x70,0x00,0x00,0x70,0x00,0x00,0x70,0x00,0x00,0x70,0x00,      
  222. 0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,      
  223. 0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0x70,0x00,0x00,      
  224. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  225. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  226. 0x00,      
  227. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                           //8      
  228. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  229. 0x00,0x00,0x00,0xFF,0x00,0x03,0x81,0xC0,0x07,0x00,0xE0,      
  230. 0x0E,0x00,0x70,0x0C,0x00,0x70,0x1C,0x00,0x38,0x1C,0x00,      
  231. 0x38,0x1C,0x00,0x38,0x1C,0x00,0x38,0x1E,0x00,0x38,0x0F,      
  232. 0x00,0x70,0x0F,0x80,0x70,0x07,0xC0,0xE0,0x03,0xF1,0xC0,      
  233. 0x01,0xFF,0x00,0x01,0xFF,0x00,0x03,0x1F,0x80,0x06,0x07,      
  234. 0xC0,0x0E,0x03,0xE0,0x1C,0x00,0xF0,0x1C,0x00,0xF0,0x38,      
  235. 0x00,0x78,0x38,0x00,0x38,0x38,0x00,0x38,0x38,0x00,0x38,      
  236. 0x38,0x00,0x38,0x38,0x00,0x38,0x1C,0x00,0x70,0x0C,0x00,      
  237. 0x60,0x06,0x00,0xE0,0x03,0x81,0x80,0x00,0xFE,0x00,0x00,      
  238. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  239. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  240. 0x00,      
  241. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,                            //9      
  242. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  243. 0x00,0x00,0x00,0xFC,0x00,0x03,0x83,0x00,0x06,0x00,0x80,      
  244. 0x0E,0x00,0xC0,0x1C,0x00,0x60,0x1C,0x00,0x60,0x18,0x00,      
  245. 0x30,0x38,0x00,0x30,0x38,0x00,0x30,0x38,0x00,0x38,0x38,      
  246. 0x00,0x38,0x38,0x00,0x38,0x38,0x00,0x38,0x38,0x00,0x78,      
  247. 0x1C,0x00,0x78,0x1C,0x00,0xF8,0x1E,0x01,0xB8,0x0F,0x87,      
  248. 0x38,0x07,0xFE,0x38,0x01,0xF8,0x38,0x00,0x00,0x30,0x00,      
  249. 0x00,0x70,0x00,0x00,0x70,0x00,0x00,0x70,0x00,0x00,0x60,      
  250. 0x00,0x00,0xE0,0x06,0x00,0xC0,0x0F,0x01,0xC0,0x0F,0x01,      
  251. 0x80,0x0F,0x03,0x00,0x07,0x0E,0x00,0x01,0xF8,0x00,0x00,      
  252. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  253. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,      
  254. 0x00};      
  255. void Delay(U32 x){      
  256.     U32 i, j, k;      
  257.     for(i = 0; i < x; i++)      
  258.         for(j = 0; j < 0xff; j++)      
  259.             for(k = 0; k < 0xff; k++)      
  260.                 ;      
  261. }      
  262.         
  263. void Init_LCD(){    
  264. rLCDCON1=(CLKVAL<<8)|(MMODE<<7)|(PNRMODE<<5)|(BPPMODE<<1)|0;   //设置CLKVAL,VCLK=HCLK/[(CLKVAL+1)*2],决定VM的触发方式,选择显示模式和BPP模式,暂时不要开启LCD,因为还没有设置好  
  265.        rLCDCON2=(VBPD<<24)|(LINEVAL<<14)|(VFPD<<6)|(VSPW);    //rLCDCON2,rLCDCON3和rLCDCON4主要设置时序    
  266.        rLCDCON3=(HBPD<<19)|(HOZVAL<<8)|(HFPD);    
  267.        rLCDCON4=(HSPW);    
  268.        rLCDCON5 = (BPP24BL<<12) | (INVVCLK<<10) | (INVVLINE<<9) | (INVVFRAME<<8) | (0<<7) | (INVVDEN<<6) | (PWREN<<3)  |(BSWP<<1) | (HWSWP);                         //INVVLINE和INVVFRAME需要进行翻转,因为CPU发出的是正脉冲,LCD使用的是负脉冲,所以要改变极性,PWREN使能电源信号  
  269.        rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);    
  270.        rLCDSADDR2=M5D(((U32)LCD_BUFFER+(SCR_XSIZE*SCR_YSIZE*4))>>1 );    
  271.        rLCDSADDR3=PAGEWIDTH*32/16;    
  272.        rLCDINTMSK|=(3);          
  273.        rTCONSEL = 0;               
  274.        rGPCUP = 0x0;    
  275.        rGPDCON = 0xaaaaaaaa;    
  276.        rGPCCON = 0xaaaa02a9;    
  277.        rGPDUP = 0x0;    
  278.        rGPGUP=rGPGUP&(~(1<<4))|(1<<4);          
  279.        rGPGCON=rGPGCON&(~(3<<8))|(3<<8);     
  280.        rLCDCON1 |= 1;   //使能数据输出和LCD控制信号  
  281. }          
  282.         
  283. void Paint_text(U32 x, U32 y, U32 color, unsigned char ch[], U32 lengx, U32 lengy){  //我的这个函数是通用的,只要正确传递参数    
  284.     int i, j, test, t = -1;         
  285.     for(i = 0; i < lengy; i++){            
  286.         for(j = 0; j < lengx; j++){         
  287.             if(j%8 == 0){         
  288.                 test = 0x80;         
  289.                 t++;         
  290.             }         
  291.             if(ch[t] & test)         
  292.                 LCD_BUFFER[x+i][y+j] = color;         
  293.             test >>= 1;            
  294.         }           
  295.     }         
  296. }         
  297.         
  298. void Paint_background(U32 c, U32 startx, U32 starty, U32 endx, U32 endy){      
  299.     U32 i,j;         
  300.     for(j = starty; j < endy; j++)         
  301.         for(i = startx; i < endx; i++)         
  302.             LCD_BUFFER[j][i] = c;         
  303. }         
  304. U32 readAD(U32 ch){      
  305.     rADCCON = (1<<14)|(49<<6)|(ch<<3);      
  306.     rADCCON |= 0x1;      
  307.     while(rADCCON & 0x1);      
  308.     while(!(rADCCON & 0x8000));      
  309.     return ((U32)rADCDAT0 & 0x3ff)*99/0x3ff ;      
  310. }      
  311.         
  312. int LcdMain(){      
  313.     U32 temperature, pre[2];      
  314.     pre[0] = pre[1] = 0;         
  315.     Init_LCD();         
  316.     Paint_background(0xFFFFFF,0,0,LCD_XSIZE,LCD_YSIZE);      
  317.     Paint_text(100, 20, 0x0, wen, 48, 48);      
  318.     Paint_text(100, 68, 0x0, du, 48, 48);      
  319.     Paint_text(100, 116, 0x0, s1, 48, 48);      
  320.     Paint_text(100, 212, 0x0, s2, 48, 48);      
  321.     while(1){      
  322.         temperature = readAD(0);                                       //读取温度    
  323.         if(temperature / 10 != pre[1]){                               //如果温度改变了,调节LCD上显示的温度,如果没有改变跳过    
  324.             pre[1] = temperature/10;      
  325.             Paint_background(0xFFFFFF,164,100,164+24,100+48);      
  326.             Paint_text(100, 164, 0x0, num+pre[1]*144,24,48);     //因为每个数字占24*48/8=144个字节,所以num+offset就可以定位      
  327.         }      
  328.         if(temperature %10 != pre[0]){      
  329.             pre[0] = temperature%10;      
  330.             Paint_background(0xFFFFFF,188,100,188+24,100+48);      
  331.             Paint_text(100, 188, 0x0, num+pre[0]*144,24,48);                      
  332.         }      
  333.         Delay(100);      
  334.     }         

你可能感兴趣的:(c,buffer,2010,delay)