?? mini51b_driver.c
字號(hào):
#include "Mini51B.H" //所有與硬件相關(guān)的接口函數(shù)定義
/*ADC1549數(shù)據(jù)讀取,首次無效*/
/*/讀取ADC結(jié)果函數(shù)
unsigned int read_adc(void)
{
unsigned char i;
unsigned int temp=0;
ADC_CS = 0; //開啟控制電路,使能DA和CK IO引腳
for(i=0;i<10;i++) { //采集10次 ,即10bit
ADC_CK = 0;
temp <<= 1;
if(ADC_DA) temp++;
ADC_CK = 1;
}
ADC_CS = 1;
return(temp);
}
/*DAC5615數(shù)據(jù)寫入函數(shù)/
void write_dac(uint da)
{
uchar i;
da <<= 6;//10有效數(shù)據(jù)左對(duì)齊
DAC_CS = 0;
DAC_CK = 0;
for (i=0;i<12;i++)
{
DAC_DA = (bit)(da & 0x8000);
DAC_CK = 1;
da <<= 1;
DAC_CK = 0;
}
DAC_CS = 1;
DAC_CK = 0;
}//*/
//通用數(shù)碼管顯示函數(shù),傳入數(shù)據(jù)0~9999
void seg7_disp(uint number)
{
unsigned char code tab1[20]= {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,};
unsigned char temp,flag=0;
if(number < 10000)
{
//千位數(shù)碼管
temp = number/1000%10;
if (temp) {
SEG_Q = tab1[temp];
flag = 1;
}
else {
SEG_Q = 0xff;//數(shù)碼管熄滅
flag = 0;
}
//百位數(shù)碼管
temp = number/100%10;
if(flag | temp) {
SEG_B = tab1[temp];
flag = 1;
}
else {
SEG_B = 0xff;//數(shù)碼管熄滅
flag = 0;
}
//十位數(shù)碼管
temp = number/10%10;
if(flag | temp) SEG_S = tab1[temp];
else SEG_S = 0xff;//數(shù)碼管熄滅
//個(gè)位數(shù)碼管
temp = number%10;
SEG_G = tab1[temp];
}
else {
SEG_Q = 0xbf;//"-"
SEG_B = 0xbf;
SEG_S = 0xbf;
SEG_G = 0xbf;
}
}//*/
//延時(shí)nms子程序,
void delay_ms(unsigned int n)
{
unsigned char j;
while(n--)
for(j=0;j<230;j++);//230是實(shí)驗(yàn)測(cè)試所得!
/*
參數(shù)n>0;
延時(shí) 1ms:delay_ms(1);
延時(shí) 11ms:delay_ms(11);
……
*/
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -