找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1368|回复: 0
打印 上一主题 下一主题
收起左侧

单片机320*240显示屏操作范例

[复制链接]
跳转到指定楼层
楼主
ID:978751 发表于 2021-11-6 20:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. #define uint unsigned int
  2. #define uchar unsigned char
  3. #define xchar unsigned char code
  4. sbit A0 = P2^0;
  5. sbit WRR = P3^6;
  6. sbit RDD = P3^7;
  7. sbit CS = P2^7;
  8. sbit RES = P2^4;
  9. sbit BF = ACC^7;
  10. uchar code num_8x16[11][16];
  11. uchar code num_24x48[11][144];
  12. uchar code hui_32x32[];
  13. uchar code jing_32x32[];
  14. uchar code ke_32x32[];
  15. uchar code ji_32x32[];
  16. uchar code num_16x24_2[];
  17. uchar code num_16x24_4[];
  18. uchar code num_16x24_0[];
  19. uchar code num_16x24_x[];
  20. uchar code num_16x24_1[];
  21. uchar code num_16x24_3[];
  22. uchar code hui2_24x24[];
  23. uchar code jiu_24x24[];
  24. uchar code jiao_24x24[];
  25. uchar code dian_24x24[];
  26. uchar code jing2_24x24[];
  27. uchar code ping_24x24[];
  28. uchar code zi_24x24[];
  29. uchar code sang_24x24[];
  30. uint i,data1,temp,data2,j,k;
  31. uchar m1,num,ii,z,z1,d,d1,s,s1,s10,s100;
  32. bit k1;

  33. void delayms(uint v)
  34. { while(v!=0)v--;}

  35. void time_nms(unsigned int x)//0.5ms
  36. {
  37. unsigned char j;
  38. while(x--)
  39. {for(j=0;j<50;j++)
  40. {;}
  41. }
  42. }

  43. void delay(uint nn)
  44. {
  45. uint mm;
  46. while(nn-->0)
  47. for(mm=0;mm<1000;mm++) { };
  48. }

  49. void busy()
  50. {
  51. CS=0;A0=0;
  52. do
  53. { P0=0xff;RDD=0;delayms(1);ACC=P0;RDD=1;}
  54. while(BF==1);
  55. }

  56. void wcomd(uint cdat)
  57. {
  58. busy();
  59. A0=1;RDD=1;P0=cdat;WRR=0;WRR=1;CS=1;
  60. }

  61. void wdata(uint ddat)
  62. {
  63. busy();
  64. A0=0;RDD=1;P0=ddat;WRR=0;WRR=1;CS=1;
  65. }

  66. void wcode(uint csrl,uint csrh)
  67. {
  68. uint temdat1=0,temdat2=0;
  69. temdat1=csrl+40*csrh;
  70. temdat2=temdat1/256;
  71. temdat1=temdat1%256;
  72. wcomd(0x46);
  73. wdata(temdat1);
  74. wdata(temdat2);
  75. wcomd(0x42);
  76. }

  77. void initial()
  78. {
  79. //uint i=0
  80. wcomd(0x40); //初始化设置指令( 8)
  81. wdata(0x30);
  82. wdata(0x87);
  83. wdata(0x07);
  84. wdata(39);
  85. wdata(66);
  86. wdata(240);
  87. wdata(40); //---P7--APL
  88. wdata(0);
  89. delayms(0x9);
  90. wcomd(0x44); //显示区域设置SCROLL
  91. wdata(0x00);//P1 SAD1L
  92. wdata(0x00);
  93. wdata(240);
  94. wdata(0x80);//P4 SAD2L
  95. wdata(0x25);
  96. wdata(240);
  97. wdata(0x00);//P7 SAD3L
  98. wdata(0x4b);
  99. wdata(0x00);//P9 SAD4L
  100. wdata(0x00);
  101. delayms(0x9);
  102. wcomd(0x5a); //点位移设置
  103. wdata(0x00);
  104. delayms(0x9);
  105. wcomd(0x5b); //显示合成方式设置OYLAY
  106. wdata(0x1c);
  107. delayms(0x9);
  108. wcomd(0x59); //显示开 58H显示关
  109. wdata(0x04);
  110. delayms(0x9);
  111. wcomd(0x4c);//4C右, 4D左, 4E上, 4F下( 28页)
  112. delayms(0x9);
  113. wcomd(0x46); //光标地址
  114. wdata(0);//低8位
  115. wdata(0);//高8位
  116. delayms(0x9);
  117. }

  118. void disp_bmp(xchar *str)
  119. {
  120. uint i=0;
  121. wcode(0,0);
  122. for(i=0;i<9600;i++)
  123. { wdata(str[i]);}
  124. }
  125. void disp_all(uchar zf1,uchar zf2)
  126. {

  127. uint i=0,j=0;
  128. wcode(0x00,0x00);
  129. for(i=0;i<120;i++)
  130. {
  131. for(j=0;j<40;j++)
  132. { wdata(zf1);}
  133. for(j=0;j<40;j++)
  134. { wdata(zf2);}
  135. } }
  136. //
  137. //
  138. void ds_32x32(bit fb,uint X,uint Y,uchar *dp)//X为列坐标,以字节为单位;Y为行坐标,
  139. {
  140. uint addL;
  141. uint addH;
  142. uchar j;
  143. for(i=0;i<32;i++)
  144. {
  145. temp=0x0000+Y*40+X+40*i;
  146. addL=temp&0x00ff; //取TEMP的低八位,
  147. addH=((temp&0xff00)>>8); //取TEMP的高八位.
  148. data1=addL;
  149. data2=addH;
  150. wcomd(0x46); //显示地址
  151. wdata(data1);
  152. wdata(data2);
  153. wcomd(0x42);
  154. for(j=0;j<4;j++)
  155. {
  156. if(fb==1) wdata(*dp);
  157. else wdata(~(*dp));
  158. dp++;
  159. }
  160. }
  161. }

  162. uchar code hui_32x32[]=/*-- 宋体24; 此字体下对应的点阵为: 宽x高=32x33 --*/
  163. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x38,0x00,0x03,0xC0,0x3E,0x00,
  164. 0x03,0xC0,0x3C,0x00,0x07,0x80,0x7C,0x00,0x07,0x00,0x7E,0x00,0x07,0x00,0x77,0x00,
  165. 0x0E,0x38,0xE3,0x80,0x0C,0x3D,0xE3,0x80,0x1C,0x79,0xC1,0xE0,0x38,0x73,0x80,0xF0,
  166. 0x70,0xE7,0x00,0x7C,0x7F,0xEE,0x03,0xFE,0x31,0xDF,0xFF,0xF8,0x03,0xB8,0x00,0x60,
  167. 0x07,0x30,0x00,0x00,0x07,0x00,0x00,0x00,0x0E,0x00,0x00,0x30,0x1C,0x78,0x00,0x78,
  168. 0x3F,0xCF,0xFF,0xEC,0x3E,0x00,0x7C,0x00,0x10,0x00,0x78,0x00,0x00,0x00,0xF3,0x00,
  169. 0x00,0x38,0xE3,0x80,0x03,0xF1,0xC1,0xC0,0x3F,0x03,0x80,0xE0,0x7C,0x07,0x80,0xF0,
  170. 0x30,0x0F,0xFF,0xF0,0x00,0x07,0xC0,0x70,0x00,0x06,0x00,0x20,0x00,0x00,0x00,0x00,
  171. 0x00,0x00,0x00,0x00,
  172. };
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表