|
- /*****************************************************************************/
- /*功能:實(shí)現(xiàn)MAX517芯片的D/A轉(zhuǎn)換。沒按一次KO鍵,數(shù)字量加一,******************/
- /*顯示的模擬量增加一個(gè)單位*/
- /****************************************************************************/
- #include <reg51.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit SCL=P1^0;
- sbit SDA=P1^1;
- sbit K0=P2^0;
- void start(void)
- {
- SDA=1;
- SCL=1;
- _nop_();
- SDA=0;
- _nop_();
- }
- void stop(void)
- {
- SDA=0;
- SCL=1;
- _nop_();
- SDA=1;
- _nop_();
- }
- void ack(void)
- {
- SDA=0;
- _nop_();
- SCL=1;
- _nop_();
- SCL=0;
- }
- void send(uchar ch)
- {
- uchar BitCountter =8;
- uchar tmp;
- do
- {
- tmp=ch;
- SCL=0;
- _nop_();
- if((tmp&0x80)==0x80)
- SDA=1;
- else
- SDA=0;
- SCL=1;
- tmp=ch<<1;
- ch=tmp;
- BitCountter--;
- }
- while(BitCountter);
- SCL=0;
- }
- void DACout(uchar ch)
- {
- start();
- send(0x58);
- ack();
- send(0x00);
- ack();
- send(ch);
- ack();//
- stop();
- }
- void main(void)
- {
- uchar i;
- i=0xff;
- while(1)
- {
- if(!K0)
- {
- i++;
- while(!K0);
- }
- DACout(i);
- }
- }
復(fù)制代碼
|
|