日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導讀]// 串行數(shù)碼管顯示 TLC549 AD轉(zhuǎn)換值// 芯片 ATMEGA16L // 時鐘 4MHz 內(nèi)部 // us延時 j=1;while(--j); 一個循環(huán)6個周期,4M晶振,延時1.5us #include//164數(shù)據(jù)線置1 #define hc164_data_SET PORTD |= 0x01 //164

// 串行數(shù)碼管顯示 TLC549 AD轉(zhuǎn)換值

// 芯片 ATMEGA16L
// 時鐘 4MHz 內(nèi)部
// us延時 j=1;while(--j); 一個循環(huán)6個周期,4M晶振,延時1.5us
#include

//164數(shù)據(jù)線置1
#define hc164_data_SET PORTD |= 0x01
//164數(shù)據(jù)線清0
#define hc164_data_CLR PORTD &= ~0x01
//164時鐘線置1
#define hc164_clk_SET PORTD |= 0x02
//164時鐘線清0
#define hc164_clk_CLR PORTD &= ~0x02

void delay_nms(unsigned int); //延時 n ms
void hc164_send_byte (unsigned char byte); //164發(fā)送數(shù)據(jù)子程序
void leddisplay(void); // 數(shù)碼管顯示子程序

#define CLK549 4 // tlc549時鐘線, PD4輸出
#define DATA549 5 // tlc549數(shù)據(jù)線, PD5輸入
#define CS549 6 // tlc549片選線 ,PD6輸出

#define CLK549_SET PORTD |= 1<#define CLK549_CLR PORTD &= ~(1<#define DATA549_IN PIND&(1<TA549) // tlc549數(shù)據(jù)線, PD5輸入
#define CS549_SET PORTD |= 1<#define CS549_CLR PORTD &= ~(1<

unsigned char TLC549_ADC (void); //AD轉(zhuǎn)換子程序

unsigned char ledxs[8]={16,16,16,16,16,0,0,0}; // 數(shù)碼管顯示緩沖區(qū)
// AD轉(zhuǎn)換值 百位 十位 個位
const unsigned char tab[]={0xb7,0x12,0x67,0x76,0xd2,0xf4,0xf5,0x16,0xf7,0xf6,0xd7,0xf1,0xa5,0x73,0xe5,0xc5,0,0xff};
//共陰極代碼 0-F, 全滅,全亮
void main(void)
{
unsigned char ad_value,temp,j;
j=1;while(--j); // 一個循環(huán)6個周期,4M晶振,延時1.5us
delay_nms(200);
PORTD &= ~(1<TA549); // tlc549數(shù)據(jù)線,上拉電阻無效
DDRD = 0x53; // PD0、PD1(164驅(qū)動)置為輸出方式;
// PD4、PD6(tlc549時鐘和片選)置為輸出方式 ,PD5(tlc549數(shù)據(jù)線)置為輸入方式
while(1)
{
ad_value = TLC549_ADC(); //讀取AD轉(zhuǎn)換值
temp = ad_value/100;
ledxs[5] = temp; //求得AD轉(zhuǎn)換值百位
temp = ad_value%100;
ledxs[6] = temp/10; // 求得AD轉(zhuǎn)換值十位
ledxs[7] = temp%10; // 求得AD轉(zhuǎn)換值個位
leddisplay(); // 串行顯示
delay_nms(1000);
}
}
unsigned char TLC549_ADC(void)
{
unsigned char value=0;
unsigned char i,j;
CS549_SET;
j=2;while(--j);
CLK549_CLR;
j=4;while(--j);
CS549_CLR; //芯片起始
j=4;while(--j); //等待延時
for(i=0;i<8;i++) //輸入采樣轉(zhuǎn)換時鐘 (預采樣)
{
CLK549_SET;
j=2;while(--j);
CLK549_CLR;
j=2;while(--j);
}
CS549_SET; //開始轉(zhuǎn)換
j=20;while(--j); //等待轉(zhuǎn)換結(jié)束

CLK549_CLR;
j=4;while(--j);
CS549_CLR; //開始讀取轉(zhuǎn)換結(jié)果
j=4;while(--j);
for(i=0;i<8;i++) // 讀采樣值
{
CLK549_SET;
j=2;while(--j);
value<<=1;
//if((PIND&(1<TA549))==(1<TA549)) value |= 0x01; //接收1位數(shù)據(jù)
if( DATA549_IN ) value |= 0x01; //接收1位數(shù)據(jù)
CLK549_CLR;
j=2;while(--j);
}
CS549_SET;
j=20;while(--j);
return(value); //返回轉(zhuǎn)換結(jié)果
}
void leddisplay() // 數(shù)碼管顯示子程序
{
unsigned char i,j;
for(i=0;i<8;i++)
{
hc164_send_byte (tab[ledxs[i]]);
j=2;while(--j);
}
}
void hc164_send_byte (unsigned char byte) //164發(fā)送數(shù)據(jù)子程序
{
unsigned char i;
for(i=0;i<8;i++)
{
if( byte & ( 1 << i ))
hc164_data_SET;
else
hc164_data_CLR;
hc164_clk_SET;
hc164_clk_CLR;
}
}
void delay_nms(unsigned int k) //延時 n ms
{
while(k) //4M晶振,一個循環(huán)1ms
{
int i;
i=700;
while(i--);
k=k-1;
}
}

本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉