標(biāo)題: 實(shí)現(xiàn)MAX517芯片的D/A轉(zhuǎn)換程序。按一次KO鍵,數(shù)字量加一 [打印本頁]

作者: benbens    時(shí)間: 2015-7-14 19:49
標(biāo)題: 實(shí)現(xiàn)MAX517芯片的D/A轉(zhuǎn)換程序。按一次KO鍵,數(shù)字量加一

  1. /*****************************************************************************/
  2. /*功能:實(shí)現(xiàn)MAX517芯片的D/A轉(zhuǎn)換。沒按一次KO鍵,數(shù)字量加一,******************/
  3. /*顯示的模擬量增加一個(gè)單位*/
  4. /****************************************************************************/
  5. #include <reg51.h>
  6. #include<intrins.h>
  7. #define uchar unsigned char
  8. #define uint unsigned int
  9. sbit SCL=P1^0;
  10. sbit SDA=P1^1;
  11. sbit K0=P2^0;
  12. void start(void)
  13. {
  14. SDA=1;
  15. SCL=1;
  16. _nop_();
  17. SDA=0;
  18. _nop_();
  19. }
  20. void stop(void)
  21. {
  22. SDA=0;
  23. SCL=1;
  24. _nop_();
  25. SDA=1;
  26. _nop_();
  27. }
  28. void ack(void)
  29. {
  30. SDA=0;
  31. _nop_();
  32. SCL=1;
  33. _nop_();
  34. SCL=0;
  35. }
  36. void send(uchar ch)
  37. {
  38. uchar BitCountter =8;
  39. uchar tmp;
  40. do
  41. {
  42. tmp=ch;
  43. SCL=0;
  44. _nop_();
  45. if((tmp&0x80)==0x80)
  46. SDA=1;
  47. else
  48. SDA=0;
  49. SCL=1;
  50. tmp=ch<<1;
  51. ch=tmp;
  52. BitCountter--;
  53. }
  54. while(BitCountter);
  55. SCL=0;
  56. }
  57. void DACout(uchar ch)
  58. {
  59. start();
  60. send(0x58);
  61. ack();
  62. send(0x00);
  63. ack();
  64. send(ch);
  65. ack();//
  66. stop();
  67. }
  68. void main(void)
  69. {
  70. uchar i;
  71. i=0xff;
  72. while(1)
  73. {
  74. if(!K0)
  75. {
  76. i++;
  77. while(!K0);
  78. }
  79. DACout(i);
  80. }
  81. }
復(fù)制代碼








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