找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3942|回复: 0
收起左侧

Proteus仿真ds12c887+lcd1602的电子万年历

[复制链接]
ID:292554 发表于 2018-3-17 12:54 | 显示全部楼层 |阅读模式
453.jpg
  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. sbit rs=P2^5;
  5. sbit rw=P2^6;
  6. sbit duanxuan=P2^5;
  7. sbit weixuan=P2^6;
  8. sbit en=P2^4;
  9. sbit input_si=P1^0;
  10. sbit sck=P2^3;
  11. sbit lck=P1^4;
  12. sbit dsds=P1^0;
  13. sbit dsrw=P1^1;
  14. sbit dsas=P1^2;
  15. sbit gnd=P3^0;
  16. sbit moshi=P3^7;
  17. sbit jia=P3^6;
  18. sbit jian=P3^5;

  19. uchar code table[]={0xc0,0xf9,0xa4,0xb0,
  20. 0x99,0x92,0x82,0xf8,0x80,0x90,0X88,0X83,
  21. 0XC6,0XA1,0X86,0X8E,0X89,0X7F,0XBF};
  22. uchar code table1[]=" 20 - - ";
  23. uchar code table2[]=" : : ";
  24. uchar ii,bb,flag;
  25. char shi,fen,miao,nian,yue,ri,week,ashi,afen,amiao;
  26. //函数申明
  27. void write_ds(uchar add,uchar date);
  28. uchar read_ds(uchar add);
  29. void write_week(uchar date);
  30. void init();
  31. void write_date(uchar aa);
  32. void write_com(uchar num);
  33. void write_sfm(char sh,fe,mia);
  34. void start();
  35. void respond();
  36. void stop();
  37. void write_byte(uchar date);
  38. uchar read_byte();
  39. void write_at(uchar address, date);
  40. uchar read_at(uchar address);
  41. void keyscan();
  42. void write_nyr(char nia2,yu,r);
  43. void hc595(uchar date);
  44. void set_time();
  45. void alarm(char ashi,uchar afen,uchar amiao);

  46. void delay(uchar z)
  47. {
  48. uchar x,y;
  49. for(x=z;x>0;x--)
  50. for(y=110;y>0;y--);
  51. }
  52. void delay1()
  53. {;;}

  54. void main()
  55. {
  56. init();
  57. while(1)
  58. {
  59. write_ds(0x0B,0x26);
  60. keyscan();
  61. if(flag==0)
  62. {
  63. miao=read_ds(0);
  64. fen=read_ds(2);
  65. shi=read_ds(4);
  66. nian=read_ds(9);
  67. yue=read_ds(8);
  68. ri=read_ds(7);
  69. week=read_ds(6);
  70. write_week(week);
  71. write_sfm(shi,fen,miao);
  72. write_nyr(nian,yue,ri);
  73. }
  74. P1=read_ds(0x0b);
  75. }
  76. }
  77. void write_ds(uchar add,uchar date)
  78. {
  79. hc595(0x02);
  80. dsas=1;
  81. dsds=1;
  82. dsrw=1;
  83. // P0=0xff;
  84. P0=add;
  85. dsas=0;
  86. dsrw=0;
  87. P0=date;
  88. dsrw=1;
  89. dsas=1;
  90. hc595(0xff);
  91. }
  92. uchar read_ds(uchar add)
  93. {
  94. uchar ds_date;
  95. hc595(0x02);
  96. dsas=1;
  97. dsds=1;
  98. dsrw=1;
  99. P0=add;
  100. dsas=0;
  101. dsds=0;
  102. P0=0xff;
  103. ds_date=P0;
  104. dsds=1;
  105. dsas=1;
  106. hc595(0xff);
  107. return ds_date;
  108. }
  109. void set_time()
  110. { write_ds(0x0b,0x06);
  111. write_ds(0x06,1);
  112. write_ds(0x07,9);
  113. write_ds(0x08,11);
  114. write_ds(0x09,15);
  115. write_ds(0,30);
  116. write_ds(2,59);
  117. write_ds(4,23);
  118. }
  119. //函数初始化模块
  120. void init()
  121. {
  122. write_ds(0x0B,0x26);
  123. alarm(0x15,0x11,0x0a);
  124. rw=0;
  125. en=0;
  126. gnd=0;
  127. EA=1;
  128. EX0=1;
  129. IT0=0;
  130. duanxuan=1;
  131. P0=0xff;
  132. duanxuan=0;
  133. weixuan=1;
  134. P0=0xff;
  135. weixuan=0;
  136. set_time();
  137. write_com(0x38);
  138. write_com(0x06);
  139. write_com(0x0c);
  140. write_com(0x80);
  141. for(ii=0;ii<15;ii++)
  142. {
  143. write_date(table1[ii]);
  144. delay(50);
  145. }
  146. write_com(0x80+0x40+4);
  147. for(ii=0;ii<8;ii++)
  148. {
  149. write_date(table2[ii]);
  150. delay(50);
  151. }
  152. }

  153. //1602显示模块
  154. void write_date(uchar aa)
  155. {
  156. rs=1;
  157. P0=aa;
  158. delay(5);
  159. en=1;
  160. delay(5);
  161. en=0;
  162. }
  163. void write_com(uchar num)
  164. {
  165. rs=0;
  166. P0=num;
  167. delay(5);
  168. en=1;
  169. delay(5);
  170. en=0;
  171. }
  172. void write_sfm(char sh,fe,mia)
  173. {
  174. write_com(0x80+0x40+10);
  175. write_date(0x30+mia/10);
  176. delay(5);
  177. write_date(0x30+mia%10);
  178. delay(5);
  179. write_com(0x80+0x40+7);
  180. write_date(0x30+fe/10);
  181. delay(5);
  182. write_date(0x30+fe%10);
  183. delay(5);
  184. write_com(0x80+0x40+4);
  185. write_date(0x30+sh/10);
  186. delay(5);
  187. write_date(0x30+sh%10);
  188. delay(5);
  189. }
  190. void write_nyr(char nia2,yu,r)
  191. {
  192. write_com(0x80+3);
  193. write_date(0x30+nia2/10);
  194. delay(5);
  195. write_date(0x30+nia2%10);
  196. delay(5);
  197. write_com(0x80+6);
  198. write_date(0x30+yu/10);
  199. delay(5);
  200. write_date(0x30+yu%10);
  201. delay(5);
  202. write_com(0x80+9);
  203. write_date(0x30+ri/10);
  204. delay(5);
  205. write_date(0x30+ri%10);
  206. delay(5);
  207. }
  208. void write_week(uchar date)
  209. {
  210. switch(date)
  211. {
  212. case 1: write_com(0x80+12);
  213. write_date('M');
  214. write_date('O');
  215. write_date('N');
  216. break;
  217. case 2: write_com(0x80+12);
  218. write_date('T');
  219. write_date('U');
  220. write_date('S');
  221. break;
  222. case 3: write_com(0x80+12);
  223. write_date('W');
  224. write_date('E');
  225. write_date('D');
  226. break;
  227. case 4: write_com(0x80+12);
  228. write_date('T');
  229. write_date('H');
  230. write_date('U');
  231. break;
  232. case 5: write_com(0x80+12);
  233. write_date('F');
  234. write_date('R');
  235. write_date('I');
  236. break;
  237. case 6: write_com(0x80+12);
  238. write_date('S');
  239. write_date('T');
  240. write_date('A');
  241. break;
  242. case 7: write_com(0x80+12);
  243. write_date('S');
  244. write_date('U');
  245. write_date('N');
  246. break;
  247. }
  248. }
  249. void hc595(uchar date)
  250. {
  251. uchar i;
  252. sck=0;
  253. for(i=0;i<8;i++)
  254. { date=date<<1;
  255. lck=0;
  256. input_si=CY;
  257. lck=1;
  258. }
  259. lck=1;
  260. sck=1;
  261. }

  262. void keyscan()
  263. { uchar num1,ii;
  264. if(moshi==0)
  265. {
  266. delay(5);
  267. if(moshi==0)
  268. {
  269. flag=1;
  270. num1++;



  271. switch(num1)
  272. {
  273. case 1: write_com(0x80+0x40+11);
  274. write_com(0x0f);
  275. break;
  276. case 2: write_com(0x80+0x40+8);
  277. // write_com(0x0f);
  278. break;
  279. case 3: write_com(0x80+0x40+5);
  280. // write_com(0x0f);
  281. break;
  282. case 4: write_com(0x80+14);
  283. // write_com(0x0f);
  284. break;
  285. case 5: write_com(0x80+10);
  286. // write_com(0x0f);
  287. break;
  288. case 6: write_com(0x80+7);
  289. // write_com(0x0f);
  290. break;
  291. case 7: write_com(0x80+4);
  292. // write_com(0x0f);
  293. break;
  294. case 8: write_ds(0,miao);
  295. write_ds(2,fen);
  296. write_ds(4,shi);
  297. write_ds(6,week);
  298. write_ds(7,ri);
  299. write_ds(8,yue);
  300. write_ds(9,nian);
  301. write_com(0x0c);
  302. flag=0;
  303. num1=0;
  304. break;
  305. }
  306. while(!moshi);
  307. }
  308. }


  309. if(num1!=0)
  310. {
  311. if(jia==0)
  312. {
  313. delay(5);
  314. if(jia==0)
  315. {
  316. while(!jia);

  317. switch(num1)
  318. {
  319. case 1:
  320. miao++;
  321. if(miao==60)miao=0;
  322. write_sfm(shi,fen,miao);
  323. write_com(0x80+0x40+11);
  324. break;
  325. case 2: fen++;
  326. if(fen==60)fen=0;
  327. write_sfm(shi,fen,miao);
  328. write_com(0x80+0x40+8);
  329. break;
  330. case 3: shi++;
  331. if(shi==24)shi=0;
  332. write_sfm(shi,fen,miao);
  333. write_com(0x80+0x40+5);
  334. break;
  335. case 4: week++;
  336. if(week==8)week=1;
  337. write_week(week);
  338. write_com(0x80+14);
  339. break;
  340. }

  341. }
  342. }
  343. if(jian==0)
  344. {
  345. delay(5);
  346. if(jian==0)
  347. {
  348. while(!jian);
  349. switch(num1)
  350. {
  351. case 1: miao--;
  352. if(miao==-1)miao=59;
  353. write_sfm(shi,fen,miao);
  354. write_com(0x80+0x40+11);
  355. break;
  356. case 2: fen--;
  357. if(fen==-1)fen=59;
  358. write_sfm(shi,fen,miao);
  359. write_com(0x80+0x40+8);
  360. break;
  361. case 3: shi--;
  362. if(shi==-1)shi=23;
  363. write_sfm(shi,fen,miao);
  364. write_com(0x80+0x40+5);
  365. break;
  366. case 4: week--;
  367. if(week==0)week=7;
  368. write_week(week);
  369. write_com(0x80+14);
  370. break;
  371. }
  372. }
  373. }
  374. }
  375. }

  376. void alarm(char ashi,uchar afen,uchar amiao)
  377. {
  378. write_ds(1,amiao);
  379. write_ds(3,afen);
  380. write_ds(5,ashi);
  381. }
  382. void exter() interrupt 0
  383. {
  384. uchar c,i;
  385. c=read_ds(0x0C);
  386. for(i=30;i>0;i--)
  387. {
  388. P1=0x55;
  389. delay(200);
  390. P1=0xaa;
  391. delay(200);
  392. }
  393. }
复制代码

贴吧仿真.7z

142.42 KB, 下载次数: 96, 下载积分: 黑币 -5

回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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