直接復(fù)制粘貼然后運(yùn)行
然后打開stc燒錄到開發(fā)板上面就能用 程序哪里不懂的話問我,我閑的蛋疼!
#include <STC15F2K60S2.H>
#include <intrins.h>
unsigned char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xff,0xc6,0x8c,0x88};
unsigned char yi,er,san,si,wu,liu,qi,ba;
long wendu;
unsigned char jiemian=0;
unsigned char canshu=25;
bit s1=0,s2=0,s3=0,s4=0;
bit moshi=0;
int shuchu;
sbit DQ = P1^4; ?//單總線接口
?? ?
#define somenop {_nop_();_nop_();_nop_();_nop_();_nop_();} ? ?
#define SlaveAddrW 0xA0
#define SlaveAddrR 0xA1
//總線引腳定義
sbit SDA = P2^1; ?/* 數(shù)據(jù)線 */
sbit SCL = P2^0; ?/* 時(shí)鐘線 */
?? ?
?? ?
?? ?
void chushihua()
{
?? ?P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;
?? ?P2=0XC0;P0=0X00;P2=0XFF;P0=0XFF;
}
void Delayms(int ms)
{
?? ?int i,j;
?? ?for(i=0;i<ms;i++)
?? ? ?for(j=845;j>0;j--);
}
void shumaguan1(unsigned char yi,unsigned char er)
{
?? ?P2=0XC0;
?? ?P0=0X01;
?? ?P2=0XFF;
?? ?P0=tab[yi];
?? ?Delayms(1);
?? ?
?? ?P2=0XC0;
?? ?P0=0X02;
?? ?P2=0XFF;
?? ?P0=tab[er];
?? ?Delayms(1);
}
void shumaguan2(unsigned char san,unsigned char si)
{
?? ?P2=0XC0;
?? ?P0=0X04;
?? ?P2=0XFF;
?? ?P0=tab[san];
?? ?Delayms(1);
?? ?
?? ?P2=0XC0;
?? ?P0=0X08;
?? ?P2=0XFF;
?? ?P0=tab[si];
?? ?Delayms(1);
}
void shumaguan3(unsigned char wu,unsigned char liu)
{
?? ?P2=0XC0;
?? ?P0=0X10;
?? ?P2=0XFF;
?? ?P0=tab[wu];
?? ?Delayms(1);
?? ?
?? ?P2=0XC0;
?? ?P0=0X20;
?? ?P2=0XFF;
?? ?P0=tab[liu];
?? ?Delayms(1);
}
void shumaguan4(unsigned char qi,unsigned char ba)
{
?? ?P2=0XC0;
?? ?P0=0X40;
?? ?P2=0XFF;
?? ?P0=tab[qi];
?? ?Delayms(1);
?? ?
?? ?P2=0XC0;
?? ?P0=0X80;
?? ?P2=0XFF;
?? ?P0=tab[ba];
?? ?Delayms(1);
}
//單總線延時(shí)函數(shù)
void Delay_OneWire(unsigned int t) ?
{
?? ?unsigned char i;
?? ?while(t--){
?? ??? ?for(i=0; i<8; i++);
?? ?}
}
//通過單總線向DS18B20寫一個(gè)字節(jié)
void Write_DS18B20(unsigned char dat)
{
?? ?unsigned char i;
?? ?for(i=0;i<8;i++)
?? ?{
?? ??? ?DQ = 0;
?? ??? ?DQ = dat&0x01;
?? ??? ?Delay_OneWire(5);
?? ??? ?DQ = 1;
?? ??? ?dat >>= 1;
?? ?}
?? ?Delay_OneWire(5);
}文章來源:http://www.zghlxwxcb.cn/news/detail-408714.html
//從DS18B20讀取一個(gè)字節(jié)
unsigned char Read_DS18B20(void)
{
?? ?unsigned char i;
文章來源地址http://www.zghlxwxcb.cn/news/detail-408714.html
到了這里,關(guān)于第十二屆藍(lán)橋杯單片機(jī)省賽的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!