[Atmel] 用AtmelStudio6.2跑mega16例程(66)显示汉字

[复制链接]
 楼主| ddllxxrr 发表于 2014-12-7 12:15 | 显示全部楼层 |阅读模式
这个例子演示了LGM12864 液晶屏的汉字显示效果,该液晶屏使用KS0108控制芯片。

Proteus运行截图:


Atmel Studio6.2编译通过截图:


程序清单:

LCD:

  1. /*
  2. * GccApplication29.c
  3. *
  4. * Created: 2014-12-7 10:45:58
  5. *  Author: Administrator
  6. */


  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9. #include <string.h>
  10. #include <stdint.h>

  11. #define LCD_START_ROW 0xc0
  12. #define LCD_PAGE 0xB8
  13. #define LCD_COL 0x40

  14. #define  RW PD0
  15. #define DI PD1
  16. #define E PD2
  17. #define CS1 PD3
  18. #define CS2 PD4
  19. #define RST PD5

  20. #define LCD_PORT PORTC
  21. #define LCD_DDR DDRC
  22. #define LCD_PIN PINC
  23. #define LCD_CTRL PORTD

  24. #define RW_1() LCD_CTRL |= _BV(RW)
  25. #define RW_0() LCD_CTRL &=~_BV(RW)
  26. #define DI_1() LCD_CTRL |= _BV(DI)
  27. #define DI_0() LCD_CTRL &=~_BV(DI)
  28. #define E_1() LCD_CTRL |= _BV(E)
  29. #define E_0() LCD_CTRL &=~_BV(E)
  30. #define CS1_1() LCD_CTRL |= _BV(CS1)
  31. #define CS1_0() LCD_CTRL &=~_BV(CS1)
  32. #define CS2_1() LCD_CTRL |= _BV(CS2)
  33. #define CS2_0() LCD_CTRL &=~_BV(CS2)
  34. #define RST_1() LCD_CTRL|= _BV(RST)
  35. #define RST_0() LCD_CTRL &=~_BV(RST)

  36. uint8_t Reverse_Display = 0;

  37. void Wait_LCD_Ready()
  38. {
  39.         Check_Busy:
  40.         LCD_DDR = 0x00;
  41.         LCD_PORT = 0xFF;
  42.         RW_1();asm("nop");DI_0();
  43.         E_1();asm("nop"); E_0();
  44.         if(LCD_PIN&0x80)goto Check_Busy;
  45. }


  46. void LCD_Write_Command(uint8_t cmd)
  47. {
  48.         Wait_LCD_Ready();
  49.         LCD_DDR = 0xFF;
  50.         LCD_PORT = 0xFF;
  51.         RW_0();asm("nop");DI_0();
  52.         LCD_PORT = cmd;
  53.         E_1();asm("nop");E_0();
  54. }

  55. void LCD_Write_Data(uint8_t dat)
  56. {
  57.         Wait_LCD_Ready();
  58.         LCD_DDR = 0xFF;
  59.         LCD_PORT = 0xff;
  60.         RW_0();asm("nop");DI_1();
  61.         if(!Reverse_Display) LCD_PORT=dat;else LCD_PORT = ~dat;
  62.         E_1();asm("nop");E_0();
  63. }

  64. void LCD_Initialize()
  65. {
  66.         LCD_Write_Command(0x3F);_delay_ms(15);
  67. }

  68. //从第P页L列开始显示W个字节数据,数据在r所指向的缓冲
  69. void Common_Show(uint8_t P,uint8_t L,uint8_t W,uint8_t *r)
  70. {
  71.         uint8_t i;
  72.         if(L<64)
  73.         {
  74.                 CS1_1();CS2_0();
  75.                 LCD_Write_Command(LCD_PAGE + P);
  76.                 LCD_Write_Command(LCD_COL + L);
  77.                 if(L + W < 64)
  78.                 {
  79.                         for(i=0;i<W;i++) LCD_Write_Data(r[i]);
  80.                 }
  81.                 else
  82.                 {
  83.                         for(i=0;i<64 - L;i++) LCD_Write_Data(r[i]);
  84.                         CS1_0();CS2_1();
  85.                         LCD_Write_Command(LCD_PAGE + P);
  86.                         LCD_Write_Command(LCD_COL);
  87.                         for(i=64 - L;i<W;i++)LCD_Write_Data(r[i]);
  88.                 }
  89.                
  90.         }
  91.         else
  92.         {
  93.                 CS1_0();CS2_1();
  94.                 LCD_Write_Command(LCD_PAGE + P);
  95.                 LCD_Write_Command(LCD_COL + L - 64);
  96.                 for(i=0;i<W;i++)LCD_Write_Data(r[i]);
  97.         }
  98. }

  99. void Display_A_Char_8X16(uint8_t P,uint8_t L,uint8_t *M)
  100. {
  101.         Common_Show(P, L, 8, M);
  102.         Common_Show(P + 1,L,8,M+8);
  103. }

  104. void Display_A_WORD(uint8_t P,uint8_t L,uint8_t *M)
  105. {
  106.         Common_Show(P,L,16,M);
  107.         Common_Show(P+1,L,16,M+16);
  108. }

  109. void Display_A_WORD_String(uint8_t P,uint8_t L,uint8_t C,uint8_t *M)
  110. {
  111.         uint8_t i;
  112.         for(i=0;i<C;i++)
  113.         {
  114.                 Display_A_WORD(P,L+i * 16,M + i *32);
  115.         }
  116.        
  117. }


main:

  1. #define  F_CPU 2000000UL
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4. #include <stdint.h>
  5. extern void LCD_Initialize();
  6. extern void Display_A_WORD_String(uint8_t P,uint8_t L,uint8_t C,uint8_t *M);
  7. extern uint8_t Reverse_Display;
  8. const uint8_t WORD_Dot_Matrix[] =
  9. {
  10.         0x10,0x61,0x06,0xE0,0x18,0x84,0xe4,0x1c,0x84,0x65,0xEE,0x24,0xa4,0x64,0x04,0x00,
  11.         0x04,0x04,0xFF,0x00,0x01,0x00,0xFF,0x41,0x21,0x12,0x0c,0x1B,0x61,0xC0,0x40,0x00,
  12.        
  13.         0x00,0x00,0x00,0x00,0x7e,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x7E,0x00,0x00,0x00,0x00,
  14.         0x00,0x7f,0x25,0x25,0x25,0x25,0x7f,0x00,0x00,0x7f,0x25,0x25,0x25,0x25,0x7F,0x00,
  15.        
  16.         0x00,0x00,0xff,0x09,0x49,0x59,0xe9,0x49,0x49,0x49,0xe9,0x59,0x49,0x4f,0x00,0x00,
  17.         0x40,0x30,0x0f,0x82,0x42,0x32,0x0f,0x02,0x02,0x02,0xff,0x02,0x02,0x02,0x02,0x00,
  18.        
  19.         0x08,0x31,0x86,0x60,0x00,0xfe,0x02,0xf2,0x02,0xfe,0x00,0xf8,0x00,0x00,0xff,0x00,
  20.         0x04,0xfc,0x03,0x00,0x80,0x47,0x30,0x0f,0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00,
  21.        
  22.         0x40,0x42,0xdc,0x08,0x00,0x90,0x90,0x90,0x90,0x90,0xff,0x10,0x12,0x1c,0x10,0x00,
  23.         0x00,0x00,0x7f,0x20,0x10,0x20,0x20,0x1F,0x10,0x10,0x01,0x06,0x18,0x20,0x78,0x00,
  24.        
  25.         0x10,0x12,0xd2,0xFE,0x91,0x11,0x80,0xbf,0xa1,0xa1,0xa1,0xa1,0xbf,0x80,0x00,0x00,
  26.         0x04,0x03,0x00,0xef,0x00,0x41,0x44,0x44,0x44,0x7f,0x44,0x44,0x44,0x44,0x40,0x00,
  27.        
  28.         0x00,0x00,0xfc,0x04,0x04,0x14,0x14,0x35,0x56,0x94,0x54,0x34,0x14,0x04,0x04,0x00,
  29.         0x80,0x60,0x1f,0x00,0x01,0x01,0x01,0x41,0x81,0x7f,0x01,0x01,0x01,0x03,0x01,0x00
  30.        
  31.        
  32. };

  33. int main()
  34. {
  35.         DDRD = 0xFF; PORTD = 0xFF;
  36.         LCD_Initialize();
  37.         Display_A_WORD_String(2,8,7,(uint8_t*)WORD_Dot_Matrix);
  38.         Reverse_Display = 1;
  39.         Display_A_WORD_String(5,8,7,(uint8_t*)WORD_Dot_Matrix);
  40.         while(1);
  41. }



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
wang168506 发表于 2014-12-8 14:55 | 显示全部楼层
我我去  这玩意也能仿真啊
 楼主| ddllxxrr 发表于 2014-12-8 19:18 | 显示全部楼层
wang168506 发表于 2014-12-8 14:55
我我去  这玩意也能仿真啊

是地是地,费我老半天劲了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部