No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

927 líneas
24KB

  1. #include "LCD.h"
  2. u8 ucDispDT;
  3. static const u8 font816[38][16]=
  4. {
  5. {0xF8,0xFC,0x04,0xC4,0x24,0xFC,0xF8,0x00,0x07,0x0F,0x09,0x08,0x08,0x0F,0x07,0x00}, // -0-
  6. {0x00,0x10,0x18,0xFC,0xFC,0x00,0x00,0x00,0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00}, // -1-
  7. {0x08,0x0C,0x84,0xC4,0x64,0x3C,0x18,0x00,0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0C,0x00}, // -2-
  8. {0x08,0x0C,0x44,0x44,0x44,0xFC,0xB8,0x00,0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00}, // -3-
  9. {0xC0,0xE0,0xB0,0x98,0xFC,0xFC,0x80,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00}, // -4-
  10. {0x7C,0x7C,0x44,0x44,0xC4,0xC4,0x84,0x00,0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00}, // -5-
  11. {0xF0,0xF8,0x4C,0x44,0x44,0xC0,0x80,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00}, // -6-
  12. {0x0C,0x0C,0x04,0x84,0xC4,0x7C,0x3C,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00}, // -7-
  13. {0xB8,0xFC,0x44,0x44,0x44,0xFC,0xB8,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00}, // -8-
  14. {0x38,0x7C,0x44,0x44,0x44,0xFC,0xF8,0x00,0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00}, // -9-
  15. {0xE0,0xF0,0x98,0x8C,0x98,0xF0,0xE0,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00}, // -A- 10
  16. {0x04,0xFC,0xFC,0x44,0x44,0xFC,0xB8,0x00,0x08,0x0F,0x0F,0x08,0x08,0x0F,0x07,0x00}, // -B- 11
  17. {0xF0,0xF8,0x0C,0x04,0x04,0x0C,0x18,0x00,0x03,0x07,0x0C,0x08,0x08,0x0C,0x06,0x00}, // -C- 12
  18. {0x04,0xFC,0xFC,0x04,0x0C,0xF8,0xF0,0x00,0x08,0x0F,0x0F,0x08,0x0C,0x07,0x03,0x00}, // -D- 13
  19. {0x04,0xFC,0xFC,0x44,0xE4,0x0C,0x1C,0x00,0x08,0x0F,0x0F,0x08,0x08,0x0C,0x0E,0x00}, // -E- 14
  20. {0x04,0xFC,0xFC,0x44,0xE4,0x0C,0x1C,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00}, // -F- 15
  21. {0xF0,0xF8,0x0C,0x84,0x84,0x8C,0x98,0x00,0x03,0x07,0x0C,0x08,0x08,0x07,0x0F,0x00}, // -G- 16
  22. {0xFC,0xFC,0x40,0x40,0x40,0xFC,0xFC,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00}, // -H- 17
  23. {0x00,0x00,0x04,0xFC,0xFC,0x04,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00}, // -I- 18
  24. {0x00,0x00,0x00,0x04,0xFC,0xFC,0x04,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,0x00}, // -J- 19
  25. {0x04,0xFC,0xFC,0xC0,0xF0,0x3C,0x0C,0x00,0x08,0x0F,0x0F,0x00,0x01,0x0F,0x0E,0x00}, // -K- 20
  26. {0x04,0xFC,0xFC,0x04,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x08,0x0C,0x0E,0x00}, // -L- 21
  27. {0xFC,0xFC,0x38,0x70,0x38,0xFC,0xFC,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00}, // -M- 22
  28. {0xFC,0xFC,0x38,0x70,0xE0,0xFC,0xFC,0x00,0x0F,0x0F,0x00,0x00,0x00,0x0F,0x0F,0x00}, // -N- 23
  29. {0xF0,0xF8,0x0C,0x04,0x0C,0xF8,0xF0,0x00,0x03,0x07,0x0C,0x08,0x0C,0x07,0x03,0x00}, // -O- 24
  30. {0x04,0xFC,0xFC,0x44,0x44,0x7C,0x38,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00}, // -P- 25
  31. {0xF8,0xFC,0x04,0x04,0x04,0xFC,0xF8,0x00,0x07,0x0F,0x08,0x0E,0x3C,0x3F,0x27,0x00}, // -Q- 26
  32. {0x04,0xFC,0xFC,0x44,0xC4,0xFC,0x38,0x00,0x08,0x0F,0x0F,0x00,0x00,0x0F,0x0F,0x00}, // -R- 27
  33. {0x18,0x3C,0x64,0x44,0xC4,0x9C,0x18,0x00,0x06,0x0E,0x08,0x08,0x08,0x0F,0x07,0x00}, // -S- 28
  34. {0x00,0x1C,0x0C,0xFC,0xFC,0x0C,0x1C,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00}, // -T- 29
  35. {0xFC,0xFC,0x00,0x00,0x00,0xFC,0xFC,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00}, // -U- 30
  36. {0xFC,0xFC,0x00,0x00,0x00,0xFC,0xFC,0x00,0x01,0x03,0x06,0x0C,0x06,0x03,0x01,0x00}, // -V- 31
  37. {0xFC,0xFC,0x00,0x80,0x00,0xFC,0xFC,0x00,0x03,0x0F,0x0E,0x03,0x0E,0x0F,0x03,0x00}, // -W- 32
  38. {0x0C,0x3C,0xF0,0xC0,0xF0,0x3C,0x0C,0x00,0x0C,0x0F,0x03,0x00,0x03,0x0F,0x0C,0x00}, // -X- 33
  39. {0x00,0x3C,0x7C,0xC0,0xC0,0x7C,0x3C,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00}, // -Y- 34
  40. {0x1C,0x0C,0x84,0xC4,0x64,0x3C,0x1C,0x00,0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0E,0x00}, // -Z- 35
  41. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00}, // -.- 36
  42. {0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00,0x00}, // -:- 37
  43. };
  44. void Get_8x16_Font(u16 character ,u8* backbuf)
  45. {
  46. if( (character>='0')&&(character<='9'))
  47. {
  48. character -= '0';
  49. }
  50. #if 1
  51. else if( (character>='A')&&(character<='Z'))
  52. {
  53. character = character - 'A' + 10;
  54. }
  55. #endif
  56. else if(character == ':')
  57. {
  58. character = 37;
  59. }
  60. else if(character == '.')
  61. {
  62. character = 36;
  63. }
  64. //backbuf = (uint8 *)(Num612[character]);
  65. memcpy(backbuf, (u8 *)(font816[character]),sizeof(font816[character]));
  66. }
  67. #if 1
  68. void HexToDec(u32 tempdata,u8* buf,unsigned char bufLen)
  69. {
  70. buf[0]=tempdata/1000000000;
  71. buf[1]=tempdata/100000000-(buf[0]*10);
  72. buf[2]=tempdata/10000000-(buf[0]*100)-(buf[1]*10);
  73. buf[3]=tempdata/1000000-buf[0]*1000-buf[1]*100-buf[2]*10;
  74. buf[4]=tempdata/100000-buf[0]*10000-buf[1]*1000-buf[2]*100-buf[3]*10;
  75. buf[5]=tempdata/10000-buf[0]*100000-buf[1]*10000-buf[2]*1000-buf[3]*100-buf[4]*10;
  76. buf[6]=tempdata/1000-buf[0]*1000000-buf[1]*100000-buf[2]*10000-buf[3]*1000-buf[4]*100-buf[5]*10;
  77. buf[7]=tempdata/100-buf[0]*10000000-buf[1]*1000000-buf[2]*100000-buf[3]*10000-buf[4]*1000-buf[5]*100-buf[6]*10;
  78. buf[8]=tempdata/10-buf[0]*100000000-buf[1]*10000000-buf[2]*1000000-buf[3]*100000-buf[4]*10000-buf[5]*1000-buf[6]*100-buf[7]*10;
  79. buf[9]=tempdata-buf[0]*1000000000-buf[1]*100000000-buf[2]*10000000-buf[3]*1000000-buf[4]*100000-buf[5]*10000-buf[6]*1000-buf[7]*100-buf[8]*10;
  80. }
  81. #endif
  82. void AttenuatorConfig(void)
  83. {
  84. GPIO_InitTypeDef GPIO_InitStructure;
  85. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //1A
  86. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  87. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  88. GPIO_Init(GPIOA, &GPIO_InitStructure);
  89. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //2A
  90. //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  91. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  92. GPIO_Init(GPIOC, &GPIO_InitStructure);
  93. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //3A
  94. //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  95. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  96. GPIO_Init(GPIOC, &GPIO_InitStructure);
  97. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //4A
  98. //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  99. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  100. GPIO_Init(GPIOC, &GPIO_InitStructure);
  101. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; //5A
  102. //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  103. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  104. GPIO_Init(GPIOC, &GPIO_InitStructure);
  105. #if 1 //衰减效果最好
  106. GPIO_SetBits(GPIOA,GPIO_Pin_8);
  107. GPIO_SetBits(GPIOC,GPIO_Pin_8);
  108. GPIO_SetBits(GPIOC,GPIO_Pin_4);
  109. GPIO_SetBits(GPIOC,GPIO_Pin_5);
  110. GPIO_SetBits(GPIOC,GPIO_Pin_14);
  111. #else
  112. GPIO_ResetBits(GPIOA,GPIO_Pin_8);
  113. GPIO_ResetBits(GPIOC,GPIO_Pin_8);
  114. GPIO_ResetBits(GPIOC,GPIO_Pin_4);
  115. GPIO_ResetBits(GPIOC,GPIO_Pin_5);
  116. GPIO_ResetBits(GPIOC,GPIO_Pin_14);
  117. #endif
  118. }
  119. void lcd_init(void)
  120. {
  121. GPIO_InitTypeDef GPIO_InitStructure;
  122. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //LCD POWER
  123. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  124. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  125. GPIO_Init(GPIOC, &GPIO_InitStructure);
  126. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //LCD CS
  127. //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  128. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  129. GPIO_Init(GPIOC, &GPIO_InitStructure);
  130. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //LCD RES
  131. //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  132. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  133. GPIO_Init(GPIOC, &GPIO_InitStructure);
  134. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //LCD AO
  135. //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  136. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  137. GPIO_Init(GPIOC, &GPIO_InitStructure);
  138. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //LCD SCK
  139. //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  140. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  141. GPIO_Init(GPIOC, &GPIO_InitStructure);
  142. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //LCD SDA 不需要
  143. //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  144. //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
  145. GPIO_Init(GPIOC, &GPIO_InitStructure);
  146. GPIO_SetBits(GPIOC,GPIO_Pin_0);
  147. vDispInit(0,24);
  148. vDispClear();
  149. }
  150. void _vWriteIR_spi(u8 ucData);
  151. void _vWriteData_spi(void);
  152. void (* WriteIR)(u8); //20120502 hong 函数指针,指向 _vWriteIR 或者_vWriteIR_spi
  153. void (* WriteData)(void); //20120502 函数指针,指向_vWriteData或者_vWriteData_spi
  154. #if 0
  155. __inline void IRQEnable(void)
  156. {
  157. int tmp;
  158. __asm
  159. {
  160. MRS tmp,CPSR ///读取CPSR的值
  161. BIC tmp,tmp,#0x80 //将IRQ中断禁止位I清零,即允许IRQ中断
  162. MSR CPSR_c,tmp //设置CPSR的值
  163. }
  164. }
  165. __inline void IRQDisable(void)
  166. {
  167. int tmp;
  168. __asm
  169. {
  170. MRS tmp,CPSR ///读取CPSR的值
  171. ORR tmp,tmp,#0x80 //将IRQ中断禁止位I清零,即允许IRQ中断
  172. MSR CPSR_c,tmp //设置CPSR的值
  173. }
  174. }
  175. #endif
  176. #if 0
  177. void SetDISPDATA( u8 DISPDATA )
  178. {
  179. IO2SET = IO2SET | DISPDATA;
  180. IO2CLR = (~IO2SET) | ((~DISPDATA) &0x000000ff);
  181. }
  182. #endif
  183. u32 vI2cHzkGetStart( u32 addr /*Int32 addr*/ )
  184. {
  185. //ulong HfcAdd;
  186. u32 HfcAdd;
  187. HfcAdd = addr >> 8;
  188. HfcAdd *= 264;
  189. HfcAdd += (addr & 0xff);
  190. return ( HfcAdd );
  191. }
  192. /**************************************************************
  193. 功能 液晶屏写命令函数
  194. 参数 ucData--命令内容
  195. 设计 谢红波
  196. 日期 20080710xiehb
  197. *************************************************************/
  198. void _vWriteIR_spi(u8 ucData)
  199. {
  200. u8 i;
  201. // 关中断
  202. ucData = ucData;
  203. //IRQDisable();
  204. //SPI1_CE = 0;
  205. //P2WPin_HIGH(PIN_LCD_SDA);
  206. //LCD_SDA_OUTMODE_SET;
  207. GPIO_SetBits(GPIOC,GPIO_Pin_12);
  208. //WPin(P2, PIN_LCD_CS0, 0);
  209. //LCD_CS0_OUTMODE_CLEAR;
  210. GPIO_ResetBits(GPIOC,GPIO_Pin_2);
  211. //P2WPin_LOW(PIN_LCD_DC);
  212. //LCD_DC_OUTMODE_CLEAR;
  213. GPIO_ResetBits(GPIOC,GPIO_Pin_10);
  214. for ( i = 0; i < 8; i++ )
  215. {
  216. //P2WPin_LOW(PIN_LCD_SCL);
  217. //LCD_SCL_OUTMODE_CLEAR;
  218. GPIO_ResetBits(GPIOC,GPIO_Pin_11);
  219. if ( (ucData & 0x80) == 0 )
  220. {
  221. //P2WPin_LOW(PIN_LCD_SDA);
  222. //LCD_SDA_OUTMODE_CLEAR;
  223. GPIO_ResetBits(GPIOC,GPIO_Pin_12);
  224. }
  225. else
  226. {
  227. //P2WPin_HIGH(PIN_LCD_SDA);
  228. //LCD_SDA_OUTMODE_SET;
  229. GPIO_SetBits(GPIOC,GPIO_Pin_12);
  230. }
  231. ucData = ucData << 1;
  232. //P2WPin_HIGH(PIN_LCD_SCL);
  233. //LCD_SCL_OUTMODE_SET;
  234. GPIO_SetBits(GPIOC,GPIO_Pin_11);
  235. }
  236. //WPin(P2, PIN_LCD_CS0, 1);
  237. //LCD_CS0_OUTMODE_SET;
  238. GPIO_SetBits(GPIOC,GPIO_Pin_2);
  239. //P2WPin_HIGH(PIN_LCD_SDA);
  240. //LCD_SDA_OUTMODE_SET;
  241. GPIO_SetBits(GPIOC,GPIO_Pin_12);
  242. // 开中断
  243. //IRQEnable();
  244. //SPI1_CE = 1;
  245. }
  246. /**************************************************************
  247. 功能 液晶屏写数据函数
  248. 参数 ucDispDT--数据内容
  249. 设计 谢红波
  250. 日期 20080710xiehb
  251. *************************************************************/
  252. void _vWriteData_spi()
  253. {
  254. u8 i;
  255. // 关中断
  256. //IRQDisable();
  257. //SPI1_CE = 0;
  258. //P2WPin_HIGH(PIN_LCD_SDA);
  259. //LCD_SDA_OUTMODE_SET;
  260. GPIO_SetBits(GPIOC,GPIO_Pin_12);
  261. //WPin(P2, PIN_LCD_CS0, 0);
  262. //LCD_CS0_OUTMODE_CLEAR;
  263. GPIO_ResetBits(GPIOC,GPIO_Pin_2);
  264. //P2WPin_HIGH(PIN_LCD_DC);
  265. //LCD_DC_OUTMODE_SET;
  266. GPIO_SetBits(GPIOC,GPIO_Pin_10);
  267. for ( i = 0; i < 8; i++ )
  268. {
  269. //P2WPin_LOW(PIN_LCD_SCL);
  270. //LCD_SCL_OUTMODE_CLEAR;
  271. GPIO_ResetBits(GPIOC,GPIO_Pin_11);
  272. if ( (ucDispDT & 0x80) == 0 )
  273. {
  274. //P2WPin_LOW(PIN_LCD_SDA);
  275. //LCD_SDA_OUTMODE_CLEAR;
  276. GPIO_ResetBits(GPIOC,GPIO_Pin_12);
  277. }
  278. else
  279. {
  280. //P2WPin_HIGH(PIN_LCD_SDA);
  281. //LCD_SDA_OUTMODE_SET;
  282. GPIO_SetBits(GPIOC,GPIO_Pin_12);
  283. }
  284. ucDispDT = ucDispDT << 1;
  285. //P2WPin_HIGH(PIN_LCD_SCL);
  286. //LCD_SCL_OUTMODE_SET;
  287. GPIO_SetBits(GPIOC,GPIO_Pin_11);
  288. }
  289. //WPin(P2, PIN_LCD_CS0, 1);
  290. //LCD_CS0_OUTMODE_SET;
  291. GPIO_SetBits(GPIOC,GPIO_Pin_2);
  292. //P2WPin_HIGH(PIN_LCD_SDA);
  293. //LCD_SDA_OUTMODE_SET;
  294. GPIO_SetBits(GPIOC,GPIO_Pin_12);
  295. // 开中断
  296. //IRQEnable();
  297. //SPI1_CE = 1;
  298. }
  299. /////////////////////////////////////////////////////////////////////////////////////
  300. //******************************************************************
  301. // 名称: void _vDispAddr(uchar ucPage,uchar ucCol)
  302. // 功能: 设置显示地址
  303. // 输入: ucPage-页地址;ucCol-列地址
  304. // 返回值:
  305. //******************************************************************
  306. void _vDispAddr(u8 ucPage,u8 ucCol)
  307. {
  308. #if 0
  309. if ( GetMainBoardType () == MAINBOARD_TYPE_GENERAL )
  310. {
  311. ucCol += 1;
  312. }
  313. #endif
  314. (*WriteIR)(0xb0+ucPage); // 设置页地址
  315. (*WriteIR)(0x10+(ucCol >> 4));//modify by ljc20071017 // 设置显示开始行高4位
  316. (*WriteIR)( ucCol & 0x0f);//modify by ljc20071017 // 设置显示开始行低4位
  317. }
  318. //******************************************************************
  319. // 名称: void vDispOn()
  320. // 功能: 打开显示
  321. // 输入:
  322. // 返回值:
  323. //******************************************************************
  324. void vDispOn(void)
  325. {
  326. //have adjust
  327. (*WriteIR)(0xaf); // 设置打开显示
  328. }
  329. //******************************************************************
  330. // 名称: void vDispClear()
  331. // 功能: 清除整个显示屏
  332. // 输入:
  333. // 返回值:
  334. //******************************************************************
  335. void vDispClear(void)
  336. {
  337. u8 i,j;
  338. //have adjust
  339. for ( i = 0; i < 8; i++ )
  340. {
  341. ucDispDT = 0;
  342. _vDispAddr(i, 0);
  343. for ( j = 0; j < 133; j++ )
  344. {
  345. // 128
  346. (*WriteData)();
  347. }
  348. }
  349. (*WriteIR)(0xaf); // 打开显示
  350. (*WriteIR)(0x2f); // Power //20070913heq //20071108heq
  351. }
  352. //******************************************************************
  353. // 名称: void vDispFull()
  354. // 功能: 整个显示屏
  355. // 输入:
  356. // 返回值:
  357. //******************************************************************
  358. void vDispFull ( void )
  359. {
  360. u8 i,j;
  361. //have adjust
  362. for ( i = 0; i < 8; i++ )
  363. {
  364. _vDispAddr(i, 0);
  365. for ( j = 0; j < 133; j++ )
  366. {
  367. ucDispDT = 0xFF;
  368. (*WriteData)();
  369. }
  370. }
  371. (*WriteIR)(0xaf); // 打开显示
  372. (*WriteIR)(0x2f); // Power //20070913heq //20071108heq
  373. }
  374. //#ifdef SPI_LCD_ENABLE //20110704 liugz
  375. /********************************************
  376. SPI屏 初始化
  377. 20080710xiehb
  378. *********************************************/
  379. void vDispInit_spi(u8 mode,u8 contrast)
  380. {
  381. if ( mode )
  382. {
  383. //LCD_SDA_OUTMODE_SET;
  384. GPIO_SetBits(GPIOC,GPIO_Pin_12);
  385. delay_5us(1);
  386. //LCD_RST_OUTMODE_SET;
  387. GPIO_SetBits(GPIOC,GPIO_Pin_3);
  388. //LCD_CS0_OUTMODE_CLEAR;
  389. GPIO_ResetBits(GPIOC,GPIO_Pin_2);
  390. //vDelayMS(5);
  391. delay_ms(5);
  392. //LCD_RST_OUTMODE_CLEAR;
  393. GPIO_ResetBits(GPIOC,GPIO_Pin_3);
  394. //vDelayMS(30);
  395. delay_ms(30);
  396. //LCD_RST_OUTMODE_SET;
  397. GPIO_SetBits(GPIOC,GPIO_Pin_3);
  398. //vDelayMS(19);
  399. delay_ms(19);
  400. }
  401. //LCD_CS0_OUTMODE_CLEAR;
  402. GPIO_ResetBits(GPIOC,GPIO_Pin_2);
  403. //LCD_SDA_OUTMODE_SET;
  404. GPIO_SetBits(GPIOC,GPIO_Pin_12);
  405. //LCD_RST_OUTMODE_SET;
  406. GPIO_SetBits(GPIOC,GPIO_Pin_3);
  407. (*WriteIR)(0xe2);
  408. delay_ms(10);
  409. (*WriteIR)(0xa2); /* 1/9bias */
  410. (*WriteIR)(0xa0); /* ADC select , Normal */
  411. (*WriteIR)(0xc8); /* Common output reverse */
  412. (*WriteIR)(0xa6); /* normal display 1=on */
  413. #if 0
  414. if ( GetMainBoardType () != MAINBOARD_TYPE_GENERAL )
  415. {
  416. (*WriteIR)(0x2C);
  417. DeyNop(10);
  418. (*WriteIR)(0x2E);
  419. DeyNop(10);
  420. }
  421. #endif
  422. (*WriteIR)(0x2F); /* V/C off, V/R off, V/F on */
  423. //DeyNop(10);
  424. delay_5us(2);
  425. (*WriteIR)(0xf8); /* Common output reverse */
  426. (*WriteIR)(0x01); /* normal display 1=on */
  427. //(*WriteIR)(0x2F); /* V/C off, V/R off, V/F on */
  428. (*WriteIR)(0x24); /* internal resistor ratio */
  429. #if 0
  430. if ( contrast > MAX_CONTRAST )
  431. {
  432. contrast = 0x24;
  433. }
  434. if ( contrast < MIN_CONTRAST )
  435. {
  436. contrast = 0x24;
  437. }
  438. #else
  439. contrast = 0x27; //24
  440. #endif
  441. (*WriteIR)(0x81); /* electronic volume mode set */
  442. (*WriteIR)(contrast); /*0x31*/
  443. (*WriteIR)(0xaf); /* display on */
  444. (*WriteIR)(0x40); /* Start line Set 40-7fh 默认40 */ //20110720 liugz //60
  445. }
  446. ///20120925 hong 智能识别屏
  447. void vDispInit( u8 mode,u8 contrast )
  448. {
  449. WriteIR = _vWriteIR_spi;
  450. WriteData = _vWriteData_spi;
  451. vDispInit_spi(mode,contrast);
  452. }
  453. #if 1
  454. /*****************************************************************
  455. 函数:E_MAINBOARD_TYPE GetMainBoardType ( void )
  456. 功能:主板类型
  457. 参数:
  458. 注意:
  459. 设计:吴伟聪
  460. 时间:2014.06.28
  461. 返回:
  462. ******************************************************************/
  463. void SetLcdRow ( u8 * ucRow )
  464. {
  465. //if ( GetMainBoardType () != MAINBOARD_TYPE_GENERAL )
  466. {
  467. if ( *ucRow < 3 )
  468. {
  469. *ucRow += 2;
  470. }
  471. else
  472. {
  473. *ucRow -= 2;
  474. }
  475. }
  476. }
  477. #endif
  478. //******************************************************************
  479. // 名称: void vDispClearLine(uchar ucRow)
  480. // 功能: 清除LCD屏的一行
  481. // 输入: ucRow-行号
  482. // 返回值:
  483. //******************************************************************
  484. void vDispClearLine(u8 ucRow)
  485. {
  486. u8 i,j;
  487. SetLcdRow(&ucRow);
  488. if ( --ucRow >= 4 )
  489. {
  490. return ;
  491. }
  492. ucRow += ucRow;
  493. for ( i = 0; i < 2; i++ )
  494. {
  495. _vDispAddr(ucRow, 0);
  496. ucDispDT = 0;
  497. for ( j = 0; j < 128; j++ )
  498. {
  499. (*WriteData)();
  500. }
  501. _vDispAddr(ucRow + 1, 0);
  502. ucDispDT = 0;
  503. for (j = 0; j < 128; j++)
  504. {
  505. (*WriteData)();
  506. }
  507. }
  508. }
  509. void Display_Icon16(u8 ucRow, u8 ucCol, unsigned char *icon)
  510. {
  511. u8 pZiMo;
  512. SetLcdRow(&ucRow);
  513. if ( --ucRow >= 4 )
  514. {
  515. return ;
  516. }
  517. if ( --ucCol > 16 )
  518. {
  519. return ;
  520. }
  521. ucRow += ucRow;
  522. ucCol <<= 3;
  523. _vDispAddr(ucRow, ucCol);
  524. ucDispDT = 0x00;
  525. for ( pZiMo = 0; pZiMo < 8; pZiMo++ )
  526. {
  527. if ( icon != 0 )
  528. {
  529. ucDispDT = icon[pZiMo];
  530. }
  531. (*WriteData)();
  532. }
  533. _vDispAddr(ucRow+1, ucCol);
  534. for ( ; pZiMo < 16; pZiMo++ )
  535. {
  536. if ( icon != 0 )
  537. {
  538. ucDispDT = icon[pZiMo];
  539. }
  540. (*WriteData)();
  541. }
  542. (*WriteIR)(0xaf); // 打开显示//20070913heq
  543. (*WriteIR)(0x2f); // Power //20070913heq
  544. }
  545. void Display_Icon(u8 ucRow, u8 ucCol, unsigned char *icon,u8 size)
  546. {
  547. u8 pZiMo;
  548. SetLcdRow(&ucRow);
  549. if ( --ucRow >= 4 )
  550. {
  551. return ;
  552. }
  553. if ( --ucCol >= 16 )
  554. {
  555. return ;
  556. }
  557. ucRow += ucRow;
  558. ucCol <<= 3;
  559. _vDispAddr(ucRow, ucCol);
  560. ucDispDT = 0x00;
  561. //for ( pZiMo = 0; pZiMo < 16; pZiMo++ )
  562. for ( pZiMo = 0; pZiMo < size; pZiMo++ )
  563. {
  564. if ( icon != 0 )
  565. {
  566. ucDispDT = icon[pZiMo];
  567. }
  568. (*WriteData)();
  569. }
  570. _vDispAddr(ucRow + 1, ucCol);
  571. //for ( ; pZiMo < 32; pZiMo++ )
  572. for ( ; pZiMo < (2*size); pZiMo++ )
  573. {
  574. if ( icon != 0 )
  575. {
  576. ucDispDT = icon[pZiMo];
  577. }
  578. (*WriteData)();
  579. }
  580. (*WriteIR)(0xaf); // 打开显示//20070913heq
  581. (*WriteIR)(0x2f); // Power //20070913heq
  582. }
  583. #if 0
  584. ///AntiColor = 1 反式显示
  585. ///AntiColor = 0 正常显示
  586. void vDispStr_light(u8 ucRow, u8 ucCol, char *szData, u8 AntiColor)
  587. {
  588. u8 ZiMo[32], pZiMo;
  589. u8 ucDispT1, ucDispT2, ucDispT4;
  590. u32 uiDispT;
  591. u32 uiDispT1;
  592. //SetMayWatchDog();
  593. IWDG_Feed();
  594. //SetLcdRow(&ucRow);
  595. if ( --ucRow >= 4 )
  596. {
  597. return ;
  598. }
  599. if ( --ucCol >= 16 )
  600. {
  601. return ;
  602. }
  603. ucRow += ucRow;
  604. ucCol <<= 3; // *8
  605. while ( (*szData != 0) && (ucCol < 128) )
  606. {
  607. ucDispT1 = *szData;
  608. szData++;
  609. if ( ucDispT1 == 0xff )
  610. {
  611. return ;
  612. }
  613. //没有0XFF开始的汉字
  614. if ( ucDispT1 < 0x80 )
  615. {
  616. //ASC
  617. uiDispT = ucDispT1 << 4;
  618. //uiDispT <<= 4;
  619. pZiMo = 0;
  620. vI2cRead(vI2cHzkGetStart( uiDispT + 222080l),16,(char *)ZiMo);
  621. _vDispAddr(ucRow, ucCol);
  622. if ( AntiColor )
  623. {
  624. for ( ucDispT4 = 0; ucDispT4 < 8; ucDispT4++ )
  625. {
  626. ucDispDT = ZiMo[pZiMo++] ^ 0xFF;
  627. (*WriteData)();
  628. }
  629. _vDispAddr(ucRow + 1, ucCol);
  630. for ( ucDispT4 = 8; ucDispT4 < 16; ucDispT4++ )
  631. {
  632. ucDispDT = ZiMo[pZiMo++] ^ 0xFF;
  633. (*WriteData)();
  634. }
  635. }
  636. else
  637. {
  638. for ( ucDispT4 = 0; ucDispT4 < 8; ucDispT4++ )
  639. {
  640. ucDispDT = ZiMo[pZiMo++];
  641. (*WriteData)();
  642. }
  643. _vDispAddr(ucRow + 1, ucCol);
  644. for ( ucDispT4 = 8; ucDispT4 < 16; ucDispT4++ )
  645. {
  646. ucDispDT = ZiMo[pZiMo++];
  647. (*WriteData)();
  648. }
  649. }
  650. ucCol += 8;
  651. }
  652. else
  653. {
  654. ucDispT2 = *szData;
  655. szData++;
  656. if ( ucCol > 112 )
  657. {
  658. break;
  659. }
  660. if ( ucDispT1 >= 0xB0 )
  661. {
  662. //B0A1~F7FF
  663. ucDispT1 -= 0xAE;
  664. }
  665. else if ( ucDispT1 == 0xA1 )
  666. {
  667. //A1A1~A1FF
  668. ucDispT1 = 0;
  669. }
  670. else if ( ucDispT1 == 0xA3 )
  671. {
  672. //A3A1~A3FF
  673. ucDispT1 = 1;
  674. }
  675. else
  676. {
  677. continue;
  678. }
  679. ucDispT2 -= 0xA1;
  680. ucDispT1 <<= 1; //*2; 47
  681. uiDispT = ucDispT1 << 4;
  682. uiDispT1 = uiDispT;
  683. uiDispT <<= 1;
  684. uiDispT += uiDispT1;
  685. uiDispT -= ucDispT1;
  686. uiDispT += ucDispT2;
  687. pZiMo = 0;
  688. vI2cRead(vI2cHzkGetStart(uiDispT<<5),32,(char *)ZiMo);
  689. _vDispAddr(ucRow, ucCol);
  690. if ( AntiColor )
  691. {
  692. for ( ucDispT4 = 0; ucDispT4 < 8; ucDispT4++ )
  693. {
  694. ucDispDT = ZiMo[pZiMo++] ^ 0xFF;
  695. (*WriteData)();
  696. }
  697. }
  698. else
  699. {
  700. for ( ucDispT4 = 0; ucDispT4 < 8; ucDispT4++ )
  701. {
  702. ucDispDT = ZiMo[pZiMo++];
  703. (*WriteData)();
  704. }
  705. }
  706. if ( ucCol < 56 )
  707. {
  708. if ( AntiColor )
  709. {
  710. for ( ucDispT4 = 8; ucDispT4 < 16; ucDispT4++ )
  711. {
  712. ucDispDT = ZiMo[pZiMo++] ^ 0xFF;
  713. (*WriteData)();
  714. }
  715. }
  716. else
  717. {
  718. for ( ucDispT4 = 8; ucDispT4 < 16; ucDispT4++ )
  719. {
  720. ucDispDT = ZiMo[pZiMo++];
  721. (*WriteData)();
  722. }
  723. }
  724. }
  725. else
  726. {
  727. if ( ucCol == 56 )
  728. {
  729. _vDispAddr(ucRow, 64);
  730. }
  731. if ( AntiColor )
  732. {
  733. for ( ucDispT4 = 8; ucDispT4 < 16; ucDispT4++ )
  734. {
  735. ucDispDT = ZiMo[pZiMo++] ^ 0xFF;
  736. (*WriteData)();
  737. }
  738. }
  739. else
  740. {
  741. for ( ucDispT4 = 8; ucDispT4 < 16; ucDispT4++ )
  742. {
  743. ucDispDT = ZiMo[pZiMo++];
  744. (*WriteData)();
  745. }
  746. }
  747. }
  748. _vDispAddr(ucRow + 1, ucCol);
  749. if ( AntiColor )
  750. {
  751. for ( ucDispT4 = 16; ucDispT4 < 24; ucDispT4++ )
  752. {
  753. ucDispDT = ZiMo[pZiMo++] ^ 0xFF;
  754. (*WriteData)();
  755. }
  756. }
  757. else
  758. {
  759. for ( ucDispT4 = 16; ucDispT4 < 24; ucDispT4++ )
  760. {
  761. ucDispDT = ZiMo[pZiMo++];
  762. (*WriteData)();
  763. }
  764. }
  765. if ( ucCol < 56 )
  766. {
  767. if ( AntiColor )
  768. {
  769. for ( ucDispT4 = 24; ucDispT4 < 32; ucDispT4++ )
  770. {
  771. ucDispDT = ZiMo[pZiMo++] ^ 0xFF;
  772. (*WriteData)();
  773. }
  774. }
  775. else
  776. {
  777. for ( ucDispT4 = 24; ucDispT4 < 32; ucDispT4++ )
  778. {
  779. ucDispDT = ZiMo[pZiMo++];
  780. (*WriteData)();
  781. }
  782. }
  783. }
  784. else
  785. {
  786. if ( ucCol == 56 )
  787. {
  788. _vDispAddr(ucRow + 1, 64);
  789. }
  790. if ( AntiColor )
  791. {
  792. for ( ucDispT4 = 24; ucDispT4 < 32; ucDispT4++ )
  793. {
  794. //vI2cGetHzk();
  795. ucDispDT = ZiMo[pZiMo++] ^ 0xFF;
  796. (*WriteData)();
  797. }
  798. }
  799. else
  800. {
  801. for ( ucDispT4 = 24; ucDispT4 < 32; ucDispT4++ )
  802. {
  803. //vI2cGetHzk();
  804. ucDispDT = ZiMo[pZiMo++];
  805. (*WriteData)();
  806. }
  807. }
  808. }
  809. ucCol += 16;
  810. }
  811. }
  812. (*WriteIR)(0xaf); // 打开显示//20070913heq //20071108heq
  813. (*WriteIR)(0x2f); // Power //20070913heq //20071108heq
  814. }
  815. void vDispStr(u8 ucRow, u8 ucCol, char *szData)
  816. {
  817. vDispStr_light(ucRow,ucCol,szData,0);
  818. }
  819. #else
  820. void vDispStr(u8 ucRow, u8 ucCol, char *szData,unsigned char datalen)
  821. {
  822. u16 i;
  823. u16 temHz;
  824. u8 buf[16];
  825. if(datalen<=0)
  826. {
  827. return ;
  828. }
  829. for(i=0;i<datalen;)
  830. {
  831. temHz = *(szData+i);
  832. i +=1;
  833. Get_8x16_Font(temHz,buf);
  834. Display_Icon(ucRow,ucCol,buf,8);
  835. ucCol += 1;
  836. }
  837. }
  838. #endif