久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4252|回復(fù): 23
打印 上一主題 下一主題
收起左側(cè)

單片機(jī)自動(dòng)打鈴系統(tǒng)程序 keil報(bào)錯(cuò)一大堆

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:893765 發(fā)表于 2021-3-21 14:50 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
keil報(bào)錯(cuò)一大堆 大堆不知問題在哪里的句法錯(cuò)誤和明明聲明變量了卻說沒聲明 麻煩各位看看

單片機(jī)源程序如下:
  1. #include<reg51.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. #define KSET 0xe0
  5. #define KSET_LONG 0xe1
  6. #define KINC 0xd0
  7. #define KDEC 0xb0
  8. #define KDOWN 0x70

  9. #define AT24C02 0xa0
  10. #define DS1307 0xD0

  11. extern bit ISendStr(uchar sla,uchar suba,uchar*s,uchar no);
  12. extern bit IRcvStr(uchar sla,uchar suba,uchar*s,uchar no);
  13. extern void LCD_DispIni(void);
  14. extern void LCD_DispFill(uchar filldata);
  15. extern void LCD_DispChar(bit color,uchar cy,uchar cx,char dispdata);
  16. extern void LCD_DispStr(bit color,uchar cy,uchar cx,char*disp_str);
  17. extern void LCD_DispHZ(uchar cy,uchar cx,char dispdata);
  18. extern void LCD_DispHZStr(uchar cy,uchar cx,char*disp_str);

  19. sbit SOUND=P3^6;
  20. uchar hzmsg[7]={0,1,2,3,4,5,0xff};
  21. uchar idata alatime[16][2]={{6,00},{6,46},{6,47},{6,48},
  22.                             {10,05},{10,45},{11,40},{13,30},
  23.                             {14,10},{14,50},{15,20},{16,00},
  24.                             {16,40},{17,20},{19,30},{21,00}};
  25. uchar max[3]={24,60,60};
  26. uchar time[3]={6,45,55};
  27. uchar idata sbuf[3];

  28. bit mk;

  29. void delay(uchar t)
  30. {   uchar i;
  31.     while(t--)
  32.     for(i=0;i<250;i++);
  33. }

  34. uchar HexBcd(uchar hex)
  35. {    return(((hex/10)<<4)|(hex%10));
  36. }

  37. uchar BcdHex(uchar bcd)
  38. { uchar hex,hex1;
  39.   hex=bcd&0x0f;
  40.   hex1=(bcd>>4)*10;
  41.   return(hex+hex1);
  42. }

  43. uchar Locate(void)
  44. { uchar n;
  45.   n=0;
  46.   while(n<16)
  47.   {    if(time[0]<alatime[n][0])break;
  48.        else if((time[0]==alatime[n][0])&&(time[1]<alatime[n][1]))break;
  49.        n++;
  50.   }
  51. if(n==16)n=0;
  52. return(n);
  53. }

  54. void LCD_DispDat(bit color,uchar cy,uchar cx,char dat)
  55. { uchar str[3];
  56.   str[0]=dat/10+0x30;
  57.   str[1]=dat%10+0x30;
  58.   str[2]=0;
  59.   LCD_DispStr(color,cy,cx,str);
  60. }

  61. uchar GetKey(void)
  62. { uchar key;
  63.   uchar t;
  64.   if((key=P2&0xf0)==0xf0)return 0xff;
  65.   for(t=0;t<5;t++)delay(5);
  66.   if((key=P2&0xf0)==0xf0)return 0xff;
  67.   while((P2&0xf0)!=0xf0)
  68.   {   delay(5);
  69.       if(t<250)t++;
  70.   }
  71.   if((t>100)&&(key==0xE0))
  72.       return 0xE1;
  73.   return key;
  74. }

  75. void DispTime(void)
  76. {LCD_DispDat(0,2,4,time[0]);
  77. LCD_DispChar(0,2,6,':');
  78. LCD_DispDat(0,2,7,time[1]);
  79. LCD_DispChar(0,2,9,':');
  80. LCD_DispDat(0,2,10,time[2]);
  81. }

  82. void DispAla(bit color,uchar no)
  83. {  LCD_DispDat(color,4+no%4,8,alatime[no][0]);
  84.    LCD_DispChar(color,4+no%4,10,':');
  85.    LCD_DispDat(color,4+no%4,11,alatime[no][1]);
  86. }

  87. void DispPage(uchar page)
  88. {   uchar i;
  89.     for(i=0;i<4;i++)
  90.     {   LCD_DispChar(0,4+i,3,'(');
  91.         LCD_DispDat(0,4+i,4,page*4+i+1);
  92.         LCD_DispChar(0,4+i,6,')');
  93.         DispAla(0,page*4+i);
  94.     }
  95. }

  96. void ReadTime(void)
  97. { IRcvStr(DS1307,0x00,sbuf,3);
  98.   time[0]=BcdHex(sbuf[2]&0x3f);
  99.   time[1]=BcdHex(sbuf[1]&0x7f);
  100.   time[2]=BcdHex(sbuf[0]&0x7f);
  101. }

  102. void SetTime(void)
  103. { sbuf[0]=HexBcd(time[2]);
  104.   sbuf[1]=HexBcd(time[1]);
  105.   sbuf[2]=HexBcd(time[0]);
  106.   ISendStr(DS1307,0x00,sbuf,3);
  107. }

  108. void EditTime(void)
  109. { uchar col=0;
  110.   uchar k;
  111.   ReadTime();
  112.   DispTime();
  113.   LCD_DispDat(1,2,4,time[col]);
  114.   while(1)
  115.   { k=GetKey();
  116.     if(k==KINC)
  117.     {     time[col]++;
  118.           if(time[col]==max[col])
  119.                 time[col]=0;
  120.           LCD_DispDat(1,2,4+col*3,time[col]);
  121.     }
  122.     else if(k==KDEC)
  123.          {   time[col]--;
  124.              if(time[col]==0xff)
  125.                    time[col]=max[col]-1;
  126.              LCD_DispDat(1,2,4+col*3,time[col]);
  127.          }
  128.     else if(k==KSET)
  129.          {   LCD_DispDat(0,2,4+col*3,time[col]);
  130.              col=(col+1)%0x03;
  131.              LCD_DispDat(1,2,4+col*3,time[col]);
  132.          }
  133.     else if(k==KSET_LONG)
  134.          {   LCD_DispDat(0,2,4+col*3,time[col]);
  135.              SetTime();
  136.              break;
  137.          }
  138.   }
  139. }

  140. void EditAla(void)
  141. { uchar no=0;
  142.   uchar col=0;
  143.   uchar k;
  144.   DispPage(0);
  145.   LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
  146.   while(1)
  147.   {   k=GetKey();
  148.       if(k==KINC)
  149.       {    alatime[no][col]++;
  150.            if(alatime[no][col]==max[col])
  151.                  alatime[no][col]=0;
  152.            LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
  153.       }
  154.       else if(k==KDEC)
  155.            {   alatime[no][col]--;
  156.                if(alatime[no][col]==0xff)
  157.                   alatime[no][col]=max[col]-1;
  158.                LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
  159.            }
  160.       else if(k==KSET)
  161.            {   LCD_DispDat(0,4+(no%4),8+col*3,alatime[no][col]);
  162.                col=(col+1)%0x01;
  163.                LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
  164.            }
  165.       else if(k==KDOWN)
  166.            {   LCD_DispDat(0,4+(no%4),8+col*3,alatime[no][col]);
  167.              no++;
  168.                col=0;
  169.                if(no==16)no=0;
  170.                if(no%4==0)
  171.                   DispPage(no/4);
  172.                LCD_DispDat(1,4+(no%4),8,alatime[no][col]);
  173.            }
  174.       else if(k==KSET_LONG)
  175.            {   for(no=0,no<4;no++)
  176.              {  ISendStr(AT24C02,no*8,&alatime[no*4][0],8);
  177.                 delay(20);
  178.              }
  179.              no=0x55;
  180.              ISendStr(AT24C02,0xff,&no,1);
  181.              break;
  182.            }
  183.   }
  184. }

  185. void int0(void)interrupt 0
  186. {  mk=1;
  187. }

  188. void timer0(void)interrupt 1
  189. { static uchar n=0;
  190.   static uchar m=0;
  191.   TH0=-1000/256;
  192.   TL0=-1000%256;
  193.   n++;
  194.   if(n==200)
  195.   {   n=0;
  196.       m++;
  197.       if(m==100)
  198.       {   m=0;
  199.           TR0=0;
  200.           SOUND=0;
  201.       }
  202.   }
  203.   if(m%4==0)
  204.      SOUND=~SOUND;
  205.   else
  206.      SOUND=1;
  207. }

  208. void main(void)
  209. { uchar i;
  210.   uchar k;
  211.   mk=0;
  212.   TMOD=0x01;
  213.   TH0=-1000/256;
  214.   TL0=-1000%256;
  215.   ET0=1;

  216.   EA=1;
  217.   IT0=1;
  218.   EX0=1;
  219.   LCD_DispIni();
  220.   LCD_DispHZStr(0,1,hzmsg);

  221.   DispTime();
  222.   IRcvStr(AT24C02,0xff,&i,1);
  223.   if(i==0x55)
  224.      IRcvStr(AT24C02,0x00,&alatime[0][0],32);

  225.   SetTime();
  226.   sbuf[0]=0x10;
  227.   ISendStr(DS1307,0x07,sbuf,0x01);
  228.   delay(20);
  229.   i=Locate();

  230.   DispPage(i/4);
  231.   DispAla(1,i);
  232.   while(1)
  233.   { k=GetKey();
  234.     if(k==KSET)
  235.     {   EditTime();
  236.         i=Locate();
  237.         DispPage(i/4);
  238.         DispAla(1,i);
  239.     }
  240.     else if(k==KSET_LONG)
  241.          {  EditAla();
  242.             i=Locate();
  243.             DispPage(i/4);
  244.             DispAla(1,i);
  245.          }
  246.      if(mk==1)
  247.      { ReadTime();
  248.        mk=0;
  249.        DispTime();
  250.            if(time[2]==0)
  251.            {   if((time[1]==alatime[i][1])&&(time[0]==alatime[i][0]))
  252.                {   DispAla(0,i);
  253.                    i++;
  254.                    if(i==16)i=0;
  255.                    if(i%4==0)
  256.                    DispPage(i/4);
  257.                    DispAla(1,i);
  258.                    TR0=1;
  259.                }
  260.            }
  261.      }
  262.   }
  263. }
復(fù)制代碼

所有資料51hei提供下載:
打鈴.rar (25.38 KB, 下載次數(shù): 8)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:893765 發(fā)表于 2021-3-21 16:50 | 只看該作者
請問審核員老師在嗎 我自己沒有傳截圖和直接公開代碼 感謝您 您是天使(確信) 還有您的截圖報(bào)錯(cuò)情況和我這邊的情況不太一樣 是自行改代碼了嗎 方便稍微談?wù)勀囊娊鈫?/td>
回復(fù)

使用道具 舉報(bào)

板凳
ID:213173 發(fā)表于 2021-3-21 17:20 | 只看該作者

評(píng)分

參與人數(shù) 1黑幣 +20 收起 理由
admin + 20 回帖助人的獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

地板
ID:213173 發(fā)表于 2021-3-21 17:25 | 只看該作者
還缺少兩個(gè)H文件
LCD12864IO.H
I2C.H
回復(fù)

使用道具 舉報(bào)

5#
ID:893765 發(fā)表于 2021-3-21 18:03 | 只看該作者
wulin 發(fā)表于 2021-3-21 17:25
還缺少兩個(gè)H文件
LCD12864IO.H
I2C.H

謝謝您 請問為什么呢
回復(fù)

使用道具 舉報(bào)

6#
ID:213173 發(fā)表于 2021-3-21 20:27 | 只看該作者

請了解模塊化編程 C語言模塊化編程.pdf (1.28 MB, 下載次數(shù): 12)

回復(fù)

使用道具 舉報(bào)

7#
ID:893765 發(fā)表于 2021-3-21 22:12 | 只看該作者
wulin 發(fā)表于 2021-3-21 20:27
請了解模塊化編程

我的理解是變量聲明與函數(shù)正篇的分離 可該報(bào)錯(cuò)還是報(bào)錯(cuò)啊
回復(fù)

使用道具 舉報(bào)

8#
ID:893765 發(fā)表于 2021-3-21 22:12 | 只看該作者
wulin 發(fā)表于 2021-3-21 20:27
請了解模塊化編程

我先試試看
回復(fù)

使用道具 舉報(bào)

9#
ID:893765 發(fā)表于 2021-3-21 22:57 | 只看該作者
wulin 發(fā)表于 2021-3-21 20:27
請了解模塊化編程

弄了h文件后I2C和自動(dòng)打鈴系統(tǒng)不報(bào)錯(cuò)了 LCD12864IO還是一堆
Build target 'Target 1'
compiling LCD12864IO.c...
LCD12864IO.C(1): warning C500: LICENSE ERROR (R208: RENEW LICENSE ID CODE (LIC))
LCD12864IO.C(1): error C141: syntax error near 'cy', expected ')'
LCD12864IO.C(2): error C141: syntax error near 'code'
LCD12864IO.C(2): error C202: 'pch': undefined identifier
LCD12864IO.C(3): error C141: syntax error near 'i'
LCD12864IO.C(3): error C202: 'i': undefined identifier
LCD12864IO.C(4): error C141: syntax error near 'bit'
LCD12864IO.C(4): error C202: 'port': undefined identifier
LCD12864IO.C(5): error C202: 'cy': undefined identifier
LCD12864IO.C(6): error C202: 'cx': undefined identifier
LCD12864IO.C(7): error C202: 'pch': undefined identifier
LCD12864IO.C(8): error C141: syntax error near 'if'
LCD12864IO.C(9): error C202: 'port': undefined identifier
LCD12864IO.C(10): error C202: 'i': undefined identifier
LCD12864IO.C(13): error C202: 'port': undefined identifier
LCD12864IO.C(14): error C202: 'i': undefined identifier
LCD12864IO.C(16): error C202: 'port': undefined identifier
LCD12864IO.C(17): error C202: 'port': undefined identifier
LCD12864IO.C(18): error C202: 'i': undefined identifier
LCD12864IO.C(20): error C202: 'port': undefined identifier
LCD12864IO.C(22): error C202: 'port': undefined identifier
LCD12864IO.C(23): error C202: 'i': undefined identifier
LCD12864IO.C(25): error C202: 'port': undefined identifier
LCD12864IO.C(27): error C202: 'port': undefined identifier
LCD12864IO.C(28): error C202: 'pch': undefined identifier
LCD12864IO.C(31): error C202: 'port': undefined identifier
LCD12864IO.C(33): error C202: 'port': undefined identifier
LCD12864IO.C(34): error C202: 'i': undefined identifier
LCD12864IO.C(36): error C202: 'port': undefined identifier
LCD12864IO.C(38): error C202: 'port': undefined identifier
LCD12864IO.C(41): error C141: syntax error near 'cy', expected ')'
LCD12864IO.C(42): error C202: 'disp_str': undefined identifier
LCD12864IO.C(43): error C202: 'cy': undefined identifier
LCD12864IO.C(44): error C202: 'cx': undefined identifier
LCD12864IO.C(45): error C202: 'cy': undefined identifier
LCD12864IO.C(46): error C141: syntax error near 'disp_str'
LCD12864IO.C(47): error C202: 'cx': undefined identifier
LCD12864IO.C(48): error C202: 'cx': undefined identifier
LCD12864IO.C(48): error C202: 'cy': undefined identifier
Target not created
回復(fù)

使用道具 舉報(bào)

10#
ID:213173 發(fā)表于 2021-3-22 08:00 | 只看該作者
田所浩二單推人 發(fā)表于 2021-3-21 22:57
弄了h文件后I2C和自動(dòng)打鈴系統(tǒng)不報(bào)錯(cuò)了 LCD12864IO還是一堆
Build target 'Target 1'
compiling LCD128 ...

LCD12864IO.C文件內(nèi)容不完整,端口和變量都沒有定義。
回復(fù)

使用道具 舉報(bào)

11#
ID:139866 發(fā)表于 2021-3-23 16:48 | 只看該作者
你不能直接復(fù)制啊,有些接口變量都需要自己定義的

評(píng)分

參與人數(shù) 1黑幣 +20 收起 理由
admin + 20 回帖助人的獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

12#
ID:893765 發(fā)表于 2021-3-24 18:57 | 只看該作者
這些天比較忙才回頭再試了試 變成了這樣的狀況

1.png (277.78 KB, 下載次數(shù): 117)

1.png
回復(fù)

使用道具 舉報(bào)

13#
ID:686782 發(fā)表于 2021-3-25 10:44 | 只看該作者
田所浩二單推人 發(fā)表于 2021-3-24 18:57
這些天比較忙才回頭再試了試 變成了這樣的狀況

首先句尾分號(hào)沒加語法錯(cuò)誤,其次沒太看懂這一句是表達(dá)什么意思 pch是uchar指針,ACII_TAB明明是uchar卻拿來當(dāng)數(shù)組名跟括號(hào)

順便建議看下項(xiàng)目文件結(jié)構(gòu),別人怎么寫的,一個(gè)include頭文件解決的不用全部extern一大堆,還有extern一般是指明函數(shù)的定義在其他的文件,這里根本不需要。
回復(fù)

使用道具 舉報(bào)

14#
ID:893765 發(fā)表于 2021-3-25 11:11 | 只看該作者
OHHO 發(fā)表于 2021-3-25 10:44
首先句尾分號(hào)沒加語法錯(cuò)誤,其次沒太看懂這一句是表達(dá)什么意思 pch是uchar指針,ACII_TAB明明是uchar卻拿 ...

ASCII_TAB那句是指向字符起始列的點(diǎn)陣碼 教科書上寫的 還有如果不extern就會(huì)報(bào)錯(cuò)一堆說我沒聲明變量 笑cry
回復(fù)

使用道具 舉報(bào)

15#
ID:143767 發(fā)表于 2021-3-25 12:08 | 只看該作者
沒有頭文件你聲明了也沒用,依舊會(huì)報(bào)錯(cuò)
回復(fù)

使用道具 舉報(bào)

16#
ID:686782 發(fā)表于 2021-3-25 12:23 | 只看該作者
田所浩二單推人 發(fā)表于 2021-3-25 11:11
ASCII_TAB那句是指向字符起始列的點(diǎn)陣碼 教科書上寫的 還有如果不extern就會(huì)報(bào)錯(cuò)一堆說我沒聲明變量 笑cr ...

你確認(rèn)自己代碼沒錯(cuò)?你的代碼里面extern指明的ACSII_TAB根本不是數(shù)組地址,還有不是你加了extern不報(bào)錯(cuò)就說明這樣寫很對
我還是那個(gè)建議,好好看看別人代碼include咋寫的。。。不是杠你,可以給你寫代碼省很多力氣。。要不你就一天到晚研究這個(gè)那個(gè)變量報(bào)錯(cuò)沒聲明吧
回復(fù)

使用道具 舉報(bào)

17#
ID:207421 發(fā)表于 2021-3-25 15:00 | 只看該作者
1. I2C.c  里面Stop(),調(diào)用時(shí)用的stop()
2. LCD12864IO.c 里面ASCII_TAB,LCD_WrDat,LCD_WrCmd,  CS1等根本不知從哪里冒來的
3. 自動(dòng)打鈴系統(tǒng).c 里面ISendStr,IRcvStr,LCD_DispIni,LCD_DispFill,LCD_DispHZ,LCD_DispHZStr這些函數(shù)根本不存在,for(no=0,no<4;no++)還寫錯(cuò)了
4. 應(yīng)該學(xué)習(xí)一下框架式編程
5. 網(wǎng)上拷貝拼湊的代碼吧?不然很多函數(shù)沒有,怎么連自己都不知道

評(píng)分

參與人數(shù) 1黑幣 +20 收起 理由
admin + 20 回帖助人的獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

18#
ID:893765 發(fā)表于 2021-3-25 18:25 | 只看該作者
把缺的東西補(bǔ)了起來 出現(xiàn)了新的問題

新打鈴.rar

3.96 KB, 下載次數(shù): 1

回復(fù)

使用道具 舉報(bào)

19#
ID:893765 發(fā)表于 2021-3-25 20:29 | 只看該作者
lwh999995 發(fā)表于 2021-3-25 15:00
1. I2C.c  里面Stop(),調(diào)用時(shí)用的stop()
2. LCD12864IO.c 里面ASCII_TAB,LCD_WrDat,LCD_WrCmd,  CS1等根 ...

缺的東西都補(bǔ)上了 方便的話請問您可以看一下嗎
回復(fù)

使用道具 舉報(bào)

20#
ID:893765 發(fā)表于 2021-3-25 20:31 | 只看該作者
OHHO 發(fā)表于 2021-3-25 12:23
你確認(rèn)自己代碼沒錯(cuò)?你的代碼里面extern指明的ACSII_TAB根本不是數(shù)組地址,還有不是你加了extern不報(bào)錯(cuò) ...

全刪掉了 該補(bǔ)的也補(bǔ)上了 感謝您
回復(fù)

使用道具 舉報(bào)

21#
ID:155507 發(fā)表于 2021-3-27 08:21 | 只看該作者
錯(cuò)誤太多:主要是抄寫錯(cuò)誤,錯(cuò)用大小寫等等。
給你改了,對比一下就知道哪里錯(cuò)了。


自動(dòng)打鈴系統(tǒng).c
  1. #include<reg51.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. #define KSET 0xe0
  5. #define KSET_LONG 0xe1
  6. #define KINC 0xd0
  7. #define KDEC 0xb0
  8. #define KDOWN 0x70

  9. #define AT24C02 0xa0
  10. #define DS1307 0xD0

  11. extern bit ISendStr(uchar sla,uchar suba,uchar*s,uchar no);
  12. extern bit IRcvStr(uchar sla,uchar suba,uchar*s,uchar no);
  13. extern void LCD_DispIni(void);
  14. extern void LCD_DispFill(uchar filldata);
  15. extern void LCD_DispChar(bit color,uchar cy,uchar cx,char dispdata);
  16. extern void LCD_DispStr(bit color,uchar cy,uchar cx,char*disp_str);
  17. extern void LCD_DispHZ(uchar cy,uchar cx,char dispdata);
  18. extern void LCD_DispHZStr(uchar cy,uchar cx,char*disp_str);

  19. sbit SOUND=P3^6;
  20. uchar hzmsg[7]={0,1,2,3,4,5,0xff};
  21. uchar idata alatime[16][2]={{ 6,00},{ 6,46},{ 6,47},{ 6,48},
  22.                                 {10,05},{10,45},{11,40},{13,30},
  23.                                 {14,10},{14,50},{15,20},{16,00},
  24.                                 {16,40},{17,20},{19,30},{21,00}};
  25. uchar max[3]={24,60,60};
  26. uchar time[3]={6,45,55};
  27. uchar idata sbuf[3];

  28. bit mk;

  29. void delay(uchar t)
  30. {
  31.         uchar i;
  32.         while(t--)
  33.              for(i=0;i<250;i++);
  34. }

  35. uchar HexBcd(uchar hex)
  36. {
  37.     return(((hex/10)<<4)|(hex%10));
  38. }

  39. uchar BcdHex(uchar bcd)
  40. {
  41.         uchar hex,hex1;
  42.         hex=bcd&0x0f;
  43.         hex1=(bcd>>4)*10;
  44.         return(hex+hex1);
  45. }

  46. uchar Locate(void)
  47. {
  48.         uchar n;
  49.         n=0;
  50.         while(n<16)
  51.         {    if(time[0]<alatime[n][0])break;
  52.                 else if((time[0]==alatime[n][0])&&(time[1]<alatime[n][1]))break;
  53.                 n++;
  54.         }
  55.         if(n==16)n=0;
  56.         return(n);
  57. }

  58. void LCD_DispDat(bit color,uchar cy,uchar cx,char dat)
  59. {
  60.         uchar str[3];
  61.         str[0]=dat/10+0x30;
  62.         str[1]=dat%10+0x30;
  63.         str[2]=0;
  64.         LCD_DispStr(color,cy,cx,str);
  65. }

  66. uchar GetKey(void)
  67. {
  68.         uchar key;
  69.         uchar t;
  70.         if((key=P2&0xf0)==0xf0)return 0xff;
  71.         for(t=0;t<5;t++)delay(5);
  72.         if((key=P2&0xf0)==0xf0)return 0xff;
  73.         while((P2&0xf0)!=0xf0)
  74.         {   delay(5);
  75.                 if(t<250)t++;
  76.         }
  77.         if((t>100)&&(key==0xE0))
  78.         return 0xE1;
  79.         return key;
  80. }

  81. void DispTime(void)
  82. {
  83.         LCD_DispDat(0,2,4,time[0]);
  84.         LCD_DispChar(0,2,6,':');
  85.         LCD_DispDat(0,2,7,time[1]);
  86.         LCD_DispChar(0,2,9,':');
  87.         LCD_DispDat(0,2,10,time[2]);
  88. }

  89. void DispAla(bit color,uchar no)
  90. {
  91.         LCD_DispDat(color,4+no%4,8,alatime[no][0]);
  92.         LCD_DispChar(color,4+no%4,10,':');
  93.         LCD_DispDat(color,4+no%4,11,alatime[no][1]);
  94. }

  95. void DispPage(uchar page)
  96. {
  97.         uchar i;
  98.         for(i=0;i<4;i++)
  99.         {   LCD_DispChar(0,4+i,3,'(');
  100.                 LCD_DispDat(0,4+i,4,page*4+i+1);
  101.                 LCD_DispChar(0,4+i,6,')');
  102.                 DispAla(0,page*4+i);
  103.         }
  104. }

  105. void ReadTime(void)
  106. {
  107.         IRcvStr(DS1307,0x00,sbuf,3);
  108.         time[0]=BcdHex(sbuf[2]&0x3f);
  109.         time[1]=BcdHex(sbuf[1]&0x7f);
  110.         time[2]=BcdHex(sbuf[0]&0x7f);
  111. }

  112. void SetTime(void)
  113. {
  114.         sbuf[0]=HexBcd(time[2]);
  115.         sbuf[1]=HexBcd(time[1]);
  116.         sbuf[2]=HexBcd(time[0]);
  117.         ISendStr(DS1307,0x00,sbuf,3);
  118. }

  119. void EditTime(void)
  120. { uchar col=0;
  121.         uchar k;
  122.         ReadTime();
  123.         DispTime();
  124.         LCD_DispDat(1,2,4,time[col]);
  125.         while(1)
  126.         { k=GetKey();
  127.                 if(k==KINC)
  128.                 {     time[col]++;
  129.                         if(time[col]==max[col])
  130.                         time[col]=0;
  131.                         LCD_DispDat(1,2,4+col*3,time[col]);
  132.                 }
  133.                 else if(k==KDEC)
  134.                 {   time[col]--;
  135.                         if(time[col]==0xff)
  136.                         time[col]=max[col]-1;
  137.                         LCD_DispDat(1,2,4+col*3,time[col]);
  138.                 }
  139.                 else if(k==KSET)
  140.                 {   LCD_DispDat(0,2,4+col*3,time[col]);
  141.                         col=(col+1)%0x03;
  142.                         LCD_DispDat(1,2,4+col*3,time[col]);
  143.                 }
  144.                 else if(k==KSET_LONG)
  145.                 {   LCD_DispDat(0,2,4+col*3,time[col]);
  146.                         SetTime();
  147.                         break;
  148.                 }
  149.         }
  150. }

  151. void EditAla(void)
  152. { uchar no=0;
  153.         uchar col=0;
  154.         uchar k;
  155.         DispPage(0);
  156.         LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
  157.         while(1)
  158.         {   k=GetKey();
  159.                 if(k==KINC)
  160.                 {    alatime[no][col]++;
  161.                         if(alatime[no][col]==max[col])
  162.                         alatime[no][col]=0;
  163.                         LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
  164.                 }
  165.                 else if(k==KDEC)
  166.                 {   alatime[no][col]--;
  167.                         if(alatime[no][col]==0xff)
  168.                         alatime[no][col]=max[col]-1;
  169.                         LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
  170.                 }
  171.                 else if(k==KSET)
  172.                 {   LCD_DispDat(0,4+(no%4),8+col*3,alatime[no][col]);
  173.                         col=(col+1)%0x01;
  174.                         LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
  175.                 }
  176.                 else if(k==KDOWN)
  177.                 {   LCD_DispDat(0,4+(no%4),8+col*3,alatime[no][col]);
  178.                         no++;
  179.                         col=0;
  180.                         if(no==16)no=0;
  181.                         if(no%4==0)
  182.                         DispPage(no/4);
  183.                         LCD_DispDat(1,4+(no%4),8,alatime[no][col]);
  184.                 }
  185.                 else if(k==KSET_LONG)
  186.                 {   for(no=0;no<4;no++)
  187.                         {  ISendStr(AT24C02,no*8,&alatime[no*4][0],8);
  188.                                 delay(20);
  189.                         }
  190.                         no=0x55;
  191.                         ISendStr(AT24C02,0xff,&no,1);
  192.                         break;
  193.                 }
  194.         }
  195. }

  196. void main(void)
  197. {
  198.         uchar i;
  199.         uchar k;
  200.         mk=0;
  201.         TMOD=0x01;
  202.         TH0=-1000/256;
  203.         TL0=-1000%256;
  204.         ET0=1;

  205.         EA=1;
  206.         IT0=1;
  207.         EX0=1;
  208.         LCD_DispIni();
  209.         LCD_DispHZStr(0,1,hzmsg);

  210.         DispTime();
  211.         IRcvStr(AT24C02,0xff,&i,1);
  212.         if(i==0x55)
  213.         IRcvStr(AT24C02,0x00,&alatime[0][0],32);

  214.         SetTime();
  215.         sbuf[0]=0x10;
  216.         ISendStr(DS1307,0x07,sbuf,0x01);
  217.         delay(20);
  218.         i=Locate();

  219.         DispPage(i/4);
  220.         DispAla(1,i);
  221.         while(1)
  222.         {
  223.                 k=GetKey();
  224.                 if(k==KSET)
  225.                 {   EditTime();
  226.                         i=Locate();
  227.                         DispPage(i/4);
  228.                         DispAla(1,i);
  229.                 }
  230.                 else if(k==KSET_LONG)
  231.                 {  EditAla();
  232.                         i=Locate();
  233.                         DispPage(i/4);
  234.                         DispAla(1,i);
  235.                 }
  236.                 if(mk==1)
  237.                 { ReadTime();
  238.                         mk=0;
  239.                         DispTime();
  240.                         if(time[2]==0)
  241.                         {   if((time[1]==alatime[i][1])&&(time[0]==alatime[i][0]))
  242.                                 {   DispAla(0,i);
  243.                                         i++;
  244.                                         if(i==16)i=0;
  245.                                         if(i%4==0)
  246.                                         DispPage(i/4);
  247.                                         DispAla(1,i);
  248.                                         TR0=1;
  249.                                 }
  250.                         }
  251.                 }
  252.         }
  253. }


  254. void int0(void)interrupt 0
  255. {
  256.         mk=1;
  257. }

  258. void timer0(void)interrupt 1
  259. {
  260.         static uchar n=0;
  261.         static uchar m=0;
  262.         TH0=-1000/256;
  263.         TL0=-1000%256;
  264.         n++;
  265.         if(n==200)
  266.         {   n=0;
  267.                 m++;
  268.                 if(m==100)
  269.                 {   m=0;
  270.                         TR0=0;
  271.                         SOUND=0;
  272.                 }
  273.         }
  274.         if(m%4==0)
  275.         SOUND=~SOUND;
  276.         else
  277.         SOUND=1;
  278. }

復(fù)制代碼

LCD12864IO.c
  1. #include <reg51.h>
  2. #include <absacc.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. sbit LCD_RST=P1^0;
  6. sbit DI=P1^5;
  7. sbit RW=P1^4;
  8. sbit CS1=P1^2;
  9. sbit CS2=P1^1;
  10. sbit EN=P1^3;
  11. sbit RDY=P0^7;
  12. sfr LCD=0x80;
  13. #define LCD_DISPON 0x3f
  14. #define LCD_STARTROW 0xc0
  15. #define LCD_ADDRSTRY 0xb8
  16. #define LCD_ADDRSTRX 0x40
  17. #define P_CS1 0
  18. #define P_CS2 1

  19. uchar code  ASCII_TAB[480] =
  20. { 0x00, 0x00, 0x00, 0x00, 0x00,
  21.         0x00, 0x00, 0x9e, 0x00, 0x00,
  22.         0x00, 0x0e, 0x00, 0x0e, 0x00,
  23.         0x28, 0xfe, 0x28, 0xfe, 0x28,
  24.         0x48, 0x54, 0xfe, 0x54, 0x24,
  25.         0x46, 0x26, 0x10, 0xc8, 0xc4,
  26.         0x6c, 0x92, 0xaa, 0x44, 0xa0,
  27.         0x00, 0x0a, 0x06, 0x00, 0x00,
  28.         0x00, 0x38, 0x44, 0x82, 0x00,
  29.         0x00, 0x82, 0x44, 0x38, 0x00,
  30.         0x28, 0x10, 0x7c, 0x10, 0x28,
  31.         0x10, 0x10, 0x7c, 0x10, 0x10,
  32.         0x00, 0xa0, 0x60, 0x00, 0x00,
  33.         0x10, 0x10, 0x10, 0x10, 0x10,
  34.         0x00, 0xc0, 0xc0, 0x00, 0x00,
  35.         0x40, 0x20, 0x10, 0x08, 0x04,
  36.         0x7C, 0xA2, 0x92, 0x8A, 0x7C,  
  37.         0x84, 0xC2, 0xA2, 0x92, 0x8C,  
  38.         0x42, 0x82, 0x8A, 0x96, 0x62,  
  39.         0x30, 0x28, 0x24, 0xFE, 0x20,
  40.         0x4E, 0x8A, 0x8A, 0x8A, 0x72,  
  41.         0x78, 0x94, 0x92, 0x92, 0x60,   
  42.         0x02, 0xE2, 0x12, 0x0A, 0x06,   
  43.         0x6C, 0x92, 0x92, 0x92, 0x6C,   
  44.         0x0C, 0x92, 0x92, 0x52, 0x3C,   
  45.         0x00, 0x6C, 0x6C, 0x00, 0x00,  
  46.         0x00, 0xAC, 0x6C, 0x00, 0x00,   
  47.         0x10, 0x28, 0x44, 0x82, 0x00,   
  48.         0x28, 0x28, 0x28, 0x28, 0x28,   
  49.         0x00, 0x82, 0x44, 0x28, 0x10,   
  50.         0x04, 0x02, 0xA2, 0x12, 0x0C,
  51.         0x64, 0x92, 0xF2, 0x82, 0x7C,  
  52.         0xFC, 0x22, 0x22, 0x22, 0xFC,   
  53.         0xFE, 0x92, 0x92, 0x92, 0x6C,   
  54.         0x7C, 0x82, 0x82, 0x82, 0x44,   
  55.         0xFE, 0x82, 0x82, 0x44, 0x38,  
  56.         0xFE, 0x92, 0x92, 0x92, 0x82,  
  57.         0xFE, 0x12, 0x12, 0x12, 0x02,   
  58.         0x7C, 0x82, 0x92, 0x92, 0xF4,   
  59.         0xFE, 0x10, 0x10, 0x10, 0xFE,  
  60.         0x00, 0x82, 0xFE, 0x82, 0x00,  
  61.         0x40, 0x80, 0x82, 0x7E, 0x02,   
  62.         0xFE, 0x10, 0x28, 0x44, 0x82,   
  63.         0xFE, 0x80, 0x80, 0x80, 0x80,  
  64.         0xFE, 0x04, 0x18, 0x04, 0xFE,   
  65.         0xFE, 0x08, 0x10, 0x20, 0xFE,   
  66.         0x7C, 0x82, 0x82, 0x82, 0x7C,
  67.         0xFE, 0x12, 0x12, 0x12, 0x0C,
  68.         0x7C, 0x82, 0xA2, 0x42, 0xBC,
  69.         0xFE, 0x12, 0x32, 0x52, 0x8C,  
  70.         0x8C, 0x92, 0x92, 0x92, 0x62,
  71.         0x02, 0x02, 0xFE, 0x02, 0x02,
  72.         0x7E, 0x80, 0x80, 0x80, 0x7E,
  73.         0x3E, 0x40, 0x80, 0x40, 0x3E,
  74.         0x7E, 0x80, 0x70, 0x80, 0x7E,
  75.         0xC6, 0x28, 0x10, 0x28, 0xC6,
  76.         0x0E, 0x10, 0xE0, 0x10, 0x0E,
  77.         0xC2, 0xA2, 0x92, 0x8A, 0x86,
  78.         0x00, 0xFE, 0x82, 0x82, 0x00,
  79.         0x04, 0x08, 0x10, 0x20, 0x40,
  80.         0x00, 0x82, 0x82, 0xFE, 0x00,
  81.         0x08, 0x04, 0x02, 0x04, 0x08,
  82.         0x80, 0x80, 0x80, 0x80, 0x80,
  83.         0x00, 0x02, 0x04, 0x08, 0x00,
  84.         0x40, 0xA8, 0xA8, 0xA8, 0xF0,
  85.         0xFE, 0x90, 0x88, 0x88, 0x70,
  86.         0x70, 0x88, 0x88, 0x88, 0x40,
  87.         0x70, 0x88, 0x88, 0x90, 0xFE,
  88.         0x70, 0xA8, 0xA8, 0xA8, 0x30,
  89.         0x10, 0xFC, 0x12, 0x02, 0x04,
  90.         0x18, 0xA4, 0xA4, 0xA4, 0x7C,
  91.         0xFE, 0x10, 0x08, 0x08, 0xF0,
  92.         0x00, 0x88, 0xFA, 0x80, 0x00,
  93.         0x40, 0x80, 0x88, 0x7A, 0x00,
  94.         0xFE, 0x20, 0x50, 0x88, 0x00,
  95.         0x00, 0x82, 0xFE, 0x80, 0x00,
  96.         0xF8, 0x08, 0x30, 0x08, 0xF8,
  97.         0xF8, 0x10, 0x08, 0x08, 0xF0,
  98.         0x70, 0x88, 0x88, 0x88, 0x70,
  99.         0xF8, 0x28, 0x28, 0x28, 0x10,
  100.         0x10, 0x28, 0x28, 0x30, 0xF8,
  101.         0xF8, 0x10, 0x08, 0x08, 0x10,
  102.         0x90, 0xA8, 0xA8, 0xA8, 0x40,
  103.         0x08, 0x7E, 0x88, 0x80, 0x40,
  104.         0x78, 0x80, 0x80, 0x40, 0xF8,
  105.         0x38, 0x40, 0x80, 0x40, 0x38,
  106.         0x78, 0x80, 0x60, 0x80, 0x78,
  107.         0x88, 0x50, 0x20, 0x50, 0x88,
  108.         0x18, 0xA0, 0xA0, 0xA0, 0x78,
  109.         0x88, 0xC8, 0xA8, 0x98, 0x88,
  110.         0x00, 0x10, 0x6C, 0x82, 0x00,
  111.         0x00, 0x00, 0xFE, 0x00, 0x00,
  112.         0x00, 0x82, 0x6C, 0x10, 0x00,
  113.         0x10, 0x10, 0x54, 0x38, 0x10,
  114.         0x10, 0x38, 0x54, 0x10, 0x10};

  115.         uchar code  HZTAB[480] = {0};  //?????

  116. void LCD_WrCmd(bit port,uchar cmd)
  117. {  EN=0;
  118.         if(port)
  119.         {
  120.                 CS2=1;
  121.                 CS1=0;
  122.         }
  123.         else
  124.         {
  125.                 CS2=0;
  126.                 CS1=1;
  127.         }
  128.         DI=0;
  129.         RW=0;
  130.         EN=1;
  131.         LCD=cmd;
  132.         EN=0;
  133. }

  134. void LCD_WrDat(bit port,uchar wrdata)
  135. {  EN=0;
  136.         if(port)
  137.         {
  138.                 CS2=1;
  139.                 CS1=0;
  140.         }
  141.         else
  142.         {
  143.                 CS2=0;
  144.                 CS1=1;
  145.         }
  146.         DI=1;
  147.         RW=0;
  148.         EN=1;
  149.         LCD=wrdata;
  150.         EN=0;
  151. }


  152. void LCD_DispFill(uchar filldata)
  153. {  uchar x,y;
  154.         LCD_WrCmd(P_CS1,LCD_STARTROW);
  155.         LCD_WrCmd(P_CS2,LCD_STARTROW);
  156.         for(y=0;y<8;y++)
  157.         {   LCD_WrCmd(P_CS1,LCD_ADDRSTRY+y);
  158.                 LCD_WrCmd(P_CS1,LCD_ADDRSTRX);
  159.                 LCD_WrCmd(P_CS2,LCD_ADDRSTRY+y);
  160.                 LCD_WrCmd(P_CS2,LCD_ADDRSTRX);
  161.                 for(x=0;x<64;x++)
  162.                 {
  163.                     LCD_WrDat(P_CS1,filldata);
  164.                         LCD_WrDat(P_CS2,filldata);
  165.                 }
  166.         }
  167. }

  168. void LCD_DispIni(void)
  169. {  uint i;
  170.         LCD_RST=0;
  171.         for(i=0;i<500;i++);
  172.         LCD_RST=1;
  173.         LCD_WrCmd(P_CS1,LCD_DISPON);
  174.         LCD_WrCmd(P_CS1,LCD_STARTROW);
  175.         LCD_WrCmd(P_CS2,LCD_DISPON);
  176.         LCD_WrCmd(P_CS2,LCD_STARTROW);
  177.         LCD_DispFill(00);
  178.         LCD_WrCmd(P_CS1,LCD_ADDRSTRY+0);
  179.         LCD_WrCmd(P_CS1,LCD_ADDRSTRX+0);
  180.         LCD_WrCmd(P_CS2,LCD_ADDRSTRY+0);
  181.         LCD_WrCmd(P_CS2,LCD_ADDRSTRX+0);
  182. }

  183. void LCD_DispChar(bit color,uchar cy,uchar cx,char dispdata)
  184. {   uchar *pch;
  185.         uchar i;
  186.         bit port;
  187.         cy=cy&0x07;
  188.         cx=cx&0x0f;
  189.         pch=&ASCII_TAB[(dispdata-0X20)*5];
  190.         if((cx&0x08)==0)
  191.         {
  192.                 port=P_CS1;
  193.                 i=cx<<3;
  194.         }
  195.         else
  196.         {  port=P_CS2;
  197.                 i=(cx&0x07)<<3;
  198.         }
  199.         LCD_WrCmd(port,LCD_ADDRSTRX+i);
  200.         LCD_WrCmd(port,LCD_ADDRSTRY+cy);
  201.         for(i=0;i<5;i++);
  202.         if(color==0)
  203.         LCD_WrDat(port,0x00);
  204.         else
  205.         LCD_WrDat(port,0xff);
  206.         for(i=0;i<5;i++)
  207.         {if(color==0)
  208.                 LCD_WrDat(port,*pch);
  209.                 else
  210.                 LCD_WrDat(port,~*pch);
  211.                 pch++;
  212.         }
  213.         if(color==0)
  214.         LCD_WrDat(port,0x00);
  215.         else
  216.         LCD_WrDat(port,0xff);
  217.         for(i=0;i<5;i++)
  218.         if(color==0)
  219.         LCD_WrDat(port,0x00);
  220.         else
  221.         LCD_WrDat(port,0xff);
  222. }

  223. void LCD_DispStr(bit color,uchar cy,uchar cx,char*disp_str)
  224. {  while(*disp_str!='\0')
  225.         {
  226.                 cy=cy&0x07;
  227.                 cx=cx&0x0f;
  228.                 LCD_DispChar(color,cy,cx,*disp_str);
  229.                 disp_str++;
  230.                 cx++;
  231.                 if(cx>15)cy++;
  232.         }
  233. }

  234. void LCD_DispHZ(uchar cy, uchar cx, char dispdata)
  235. {
  236.   uchar *pdat;
  237.         uchar i,s,page;
  238.         bit port;
  239.         cy=cy&0x03;
  240.         cx=cx&0x07;
  241.         pdat=&HZTAB[dispdata*32];
  242.         if((cx&0x04)==0)
  243.         {
  244.                 port=0;
  245.                 s=cx<<4;
  246.         }
  247.         else
  248.         {
  249.                 port=1;
  250.                 s=(cx<<4)-64;
  251.         }
  252.         for(page=0;page<2;page++)
  253.         { LCD_WrCmd(port,LCD_ADDRSTRX+s);
  254.                 LCD_WrCmd(port,LCD_ADDRSTRY+(cy<<1)+page);
  255.                 for(i=0;i<5;i++);
  256.                 for(i=0;i<16;i++)
  257.                 { LCD_WrDat(port,*pdat);
  258.                         pdat++;
  259.                 }
  260.                 for(i=0;i<5;i++);
  261.         }
  262. }

  263. void LCD_DispHZStr(uchar cy,uchar cx,char*disp_str)
  264. {   while(*disp_str!=0xff)
  265.         {
  266.                 cy=cy&0x03;
  267.                 cx=cx&0x07;
  268.                 LCD_DispHZ(cy,cx,*disp_str);
  269.                 disp_str++;
  270.                 cx++;
  271.                 if(cx>7)
  272.                 {cy++;
  273.                         cx=0;
  274.                 }
  275.         }
  276. }
復(fù)制代碼

I2C.c
  1. #include <reg51.h>
  2. #include <intrins.h>
  3. #define uchar unsigned char
  4. #define delay1us() _nop_()
  5. #define delay5us() _nop_();_nop_();_nop_();_nop_();_nop_()
  6. sbit SDA=P3^5;
  7. sbit SCL=P3^4;
  8. bit ack_mk;

  9. void Start()
  10. {
  11.     SDA=1;
  12.     SCL=1;
  13.     delay5us();
  14.     SDA=0;
  15.     delay5us();
  16.     SCL=0;
  17. }

  18. void Stop()
  19. {
  20.           SDA=0;
  21.     SCL=1;
  22.     delay5us();
  23.     SDA=1;
  24.     delay5us();
  25.     SCL=0;
  26. }

  27. void Ack(void)
  28. {
  29.           SDA=0;
  30.     SCL=1;
  31.     delay5us();
  32.     SCL=0;
  33. }

  34. void NAck(void)
  35. {   SDA=1;
  36.     SCL=1;
  37.     delay5us();
  38.     SCL=0;
  39. }

  40. void SendByte(uchar c)
  41. {    uchar n;
  42.      for(n=0;n<8;n++)
  43.      {
  44.                 if(c&0x80)
  45.         SDA=1;
  46.         else
  47.             SDA=0;
  48.         SCL=1;
  49.         delay5us();
  50.         SCL=0;
  51.         c=c<<1;
  52.      }
  53.      delay5us();
  54.      SDA=1;
  55.      delay5us();
  56.      SCL=1;
  57.      delay5us();
  58.      if(SDA==1)
  59.          ack_mk=0;
  60.      else
  61.          ack_mk=1;
  62.      SCL=0;
  63. }

  64. uchar RcvByte()
  65. {
  66.   uchar c;
  67.   uchar n;
  68.   for(n=0;n<8;n++)
  69.   {
  70.         SDA=1;
  71.     SCL=1;
  72.     if(SDA==0)
  73.         c=c&0x7f;
  74.     else
  75.         c=c|0x80;
  76.     c=_crol_(c,1);
  77.     SCL=0;
  78.   }
  79.   return(c);
  80. }

  81. bit ISendStr(uchar sla, uchar suba, uchar*s, uchar n)
  82. {  uchar i;
  83.    Start();
  84.    SendByte(sla);
  85.     if(ack_mk==0)return(0);
  86.    SendByte(suba);
  87.     if(ack_mk==0)return(0);
  88.    for(i=0;i<n;i++)
  89.    {   SendByte(*s);
  90.        if(ack_mk==0)return(0);
  91.        s++;
  92.    }
  93.    Stop();
  94.    return(1);
  95. }

  96. bit IRcvStr(uchar sla, uchar suba, uchar*s, uchar n)
  97. {
  98.    uchar i;
  99.    Start();
  100.    SendByte(sla);
  101.     if(ack_mk==0)return(0);
  102.    SendByte(suba);
  103.     if(ack_mk==0)return(0);
  104.    Start();
  105.    SendByte(sla+1);
  106.       if(ack_mk==0)return(0);
  107.    for(i=0;i<n-1;i++)
  108.    {  *s=RcvByte();
  109.       Ack();
  110.       s++;
  111.    }
  112.    *s=RcvByte();
  113.    NAck();
  114.    Stop();
  115.    return(1);
  116. }
復(fù)制代碼

回復(fù)

使用道具 舉報(bào)

22#
ID:893765 發(fā)表于 2021-3-27 14:37 | 只看該作者
angmall 發(fā)表于 2021-3-27 08:21
錯(cuò)誤太多:主要是抄寫錯(cuò)誤,錯(cuò)用大小寫等等。
給你改了,對比一下就知道哪里錯(cuò)了。

您好 新帖里的新代碼已經(jīng)補(bǔ)上所有缺的東西了 請問P_CS1的P的意思是?
回復(fù)

使用道具 舉報(bào)

23#
ID:155507 發(fā)表于 2021-3-27 16:06 | 只看該作者
田所浩二單推人 發(fā)表于 2021-3-27 14:37
您好 新帖里的新代碼已經(jīng)補(bǔ)上所有缺的東西了 請問P_CS1的P的意思是?

在c語言中不能有兩個(gè)同名變量

前面 sbit CS1=P1^2; 已經(jīng)有一個(gè)CS1,所以這里 #define P_CS1 0 不能有相同的
回復(fù)

使用道具 舉報(bào)

24#
ID:893765 發(fā)表于 2021-3-27 16:22 | 只看該作者
angmall 發(fā)表于 2021-3-27 16:06
在c語言中不能有兩個(gè)同名變量

前面 sbit CS1=P1^2; 已經(jīng)有一個(gè)CS1,所以這里 #define P_CS1 0 不能有 ...

謝謝您
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 狠狠av| 日韩欧美在线不卡 | 精品国产一区二区三区在线观看 | 全免费a级毛片免费看视频免 | 在线国产欧美 | 亚洲欧美一区二区三区国产精品 | 成人免费在线播放视频 | 天天天操操操 | 久久精品国产久精国产 | 久久亚洲免费 | 黄网站免费在线 | 91美女在线 | 日韩在线免费 | 日一区二区 | 婷婷色在线 | 一区二区三区高清不卡 | av中文字幕在线 | 天堂中文在线观看 | 欧美不卡一区二区三区 | 一级免费在线视频 | 91久久国产综合久久 | 国产精品免费一区二区三区四区 | 日日操av | 国产精彩视频一区 | 久久亚洲经典 | 五月婷亚洲 | 日韩高清一区 | 亚洲综合成人网 | 久草免费在线视频 | 国产一区二区美女 | 亚洲伊人精品酒店 | 国产精品综合色区在线观看 | 国产精品免费看 | 欧美日韩亚 | 亚洲综合无码一区二区 | 亚洲综合天堂 | 午夜手机在线视频 | 中文av在线播放 | 久久国产精品72免费观看 | 黄色网址在线播放 | 欧美精品一区二区三区在线播放 |