PCF8591(AD-DA)芯片-51單片機程序
PCF8591 是8位AD-DA芯片 轉(zhuǎn)換數(shù)據(jù)0---5 對應 0--255
通信協(xié)議IIC
模擬量輸出值和電壓的關系: 輸出電壓=(參考電壓-基點電位)/255
//以下是源碼如果在網(wǎng)頁上顯示格式錯亂可以從這里下載:http://www.51hei.com/f/8591c.rar
//12MHZ晶振
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define uint unsigned int
#include "IIC.h"http://i2c庫函數(shù)
code uchar seg[]={0x28,0x7e,0xa2,0x62,0x74,0x61,0x21,0x7a,0x20,0x60}; //數(shù)碼管碼表
code uchar tab[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //數(shù)碼管位選
code uchar tab[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //數(shù)碼管位選
sbit bz=P3^3; //喇叭位
uchar outdata;//模擬量輸出值
sbit k1=P1^2 ; //模擬量輸出者增加
sbit k2=P1^1; //模擬量輸出者減少
sbit k2=P1^1; //模擬量輸出者減少
void delay(uint k) //延時子函數(shù)
{
while(k--);
}
{
while(k--);
}
void key1() //模擬輸出值增加
{
if(k1==0)
{
delay(1000);
if(k1==0)
outdata++;
}
}
{
if(k1==0)
{
delay(1000);
if(k1==0)
outdata++;
}
}
void key2() //模擬輸出值減少
{
if(k2==0)
{
delay(1000);
if(k2==0)
outdata--;
}
}
{
if(k2==0)
{
delay(1000);
if(k2==0)
outdata--;
}
}
關鍵詞:
PCF8591AD-DA芯片51單片
評論