標(biāo)題: TLC2543 AD轉(zhuǎn)換電壓程序 [打印本頁(yè)]

作者: a2875946765    時(shí)間: 2019-1-26 10:22
標(biāo)題: TLC2543 AD轉(zhuǎn)換電壓程序
通過(guò)SPI用51單片機(jī)和TLC2543進(jìn)行AD轉(zhuǎn)換讀取電壓值

單片機(jī)源程序如下:
  1. #include "reg52.h"
  2. #include"intrins.h"
  3. //void Delay500ms();                //@11.0592MHz
  4. unsigned int AD_Read()  ;
  5. //void Delay10us();                //@11.0592MHz
  6. //void Delay3000ms();                //@11.0592MHz
  7. sbit SCK= P1^0;
  8. sbit RES_CS= P1^1;
  9. sbit DI = P1^2;
  10. sbit DO = P1^3;
  11. code unsigned char seg[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};  //0-9段碼顯示
  12. int main()
  13. {
  14.         unsigned char j,a,aa,aaa,aaaa;
  15.         unsigned int advalue=0;
  16.         float value;
  17.         while(1)
  18.         {  
  19.          advalue=AD_Read();
  20. //         value=(advalue*5)/65536.0;
  21. //         advalue=value*10000;
  22.          a=advalue%10;
  23.             advalue=advalue/10;
  24.          aa=advalue%10;
  25.          advalue=advalue/10;
  26.          aaa=advalue%10;
  27.          aaaa=advalue/10;

  28.          P3=0xfe;
  29.                 P2=~seg[aaaa];
  30.                 for(j=0;j<100;j++);
  31.                 P3=0xfd;
  32.                 P2=~seg[aaa];
  33.                 for(j=0;j<100;j++);
  34.                 P3=0xfb;
  35.                 P2=~seg[aa];
  36.                 for(j=0;j<100;j++);
  37.                 P3=0xf7;
  38.                 P2=~seg[a];
  39.                 for(j=0;j<100;j++);

  40.         }
  41. }


  42. unsigned int AD_Read()
  43. {
  44. unsigned char i,j,command=0x0c;
  45. unsigned int value;
  46. RES_CS = 1;
  47. _nop_();
  48. SCK = 0;
  49. _nop_();
  50. RES_CS = 0;
  51. _nop_();
  52. for(i=8;i>0;i--)
  53. {
  54. command <<= 1;
  55. DI = CY;                      //CY為狀態(tài)寄存器進(jìn)位標(biāo)志位,將command的最高位賦給DI
  56. _nop_();
  57. SCK = 1;
  58. _nop_();
  59. SCK = 0;
  60. _nop_();
  61. value=value<<1;
  62. j=DO;
  63.         if(j==1)
  64.         {
  65.                 value|=0x01;
  66.         }
  67. }
  68. for(i=8;i>0;i--)
  69. {
  70. _nop_();
  71. SCK = 1;
  72. _nop_();
  73. SCK = 0;
  74. _nop_();
  75. value=value<<1;
  76. j=DO;
  77.         if(j==1)
  78.         {
  79.                 value|=0x01;
  80.         }
  81. }
  82. return value;

  83. }
復(fù)制代碼

所有資料51hei提供下載:
TLC2543 SPI通信.zip (31.82 KB, 下載次數(shù): 17)



作者: admin    時(shí)間: 2019-1-26 15:32
本帖需要重新編輯補(bǔ)全電路原理圖,源碼,詳細(xì)說(shuō)明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1