怎么将stm32驱动ds18b20的程序,在数码管上显示,
#include"stm32f10x.h"#include"delay.h"#include"gpio.h"#include"ds18b20.h"u16table1[]=...
#include "stm32f10x.h"
#include "delay.h"
#include "gpio.h"
#include "ds18b20.h"
u16 table1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
u16 table2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
u16 display[4];
void tem_deal(short temp);
int main(void)
{
u8 t;
stm32_SysClock72M(9);
delay_init(72);
Gpio_init();
while(1)
{
if(t==20)
{
t=0;
tem_deal(ds18b20_read());
// tem_deal(DS18B20_Get_Temp());
}
t++;
GPIOC->ODR=table1[0]; //λѡ
GPIOD->ODR=table2[display[0]]; //¶ÎÑ¡
delay_ms(1);
GPIOC->ODR=table1[1]; //λѡ
GPIOD->ODR=table2[display[1]]|0x80; //¶ÎÑ¡
delay_ms(1);
GPIOC->ODR=table1[2]; //λѡ
GPIOD->ODR=table2[display[2]]; //¶ÎÑ¡
delay_ms(1);
GPIOC->ODR=table1[3]; //λѡ
GPIOD->ODR=table2[display[3]]; //¶ÎÑ¡
delay_ms(1);
GPIOC->ODR=0x00;//ÏûÒþ
GPIOD->ODR=0x00;
}
}
void tem_deal(short temp)
{
float tm_value;
tm_value=temp;
temp=tm_value*0.625*10;
display[0]=temp/1000;
display[1]=temp%1000/100;
display[2]=temp%10000%100/10;//´Ë´¦¸Ä¾«È·¶È
display[3]=temp%10000%100%10;
// temp=temp*100;
// display[0]=temp/100;
// display[1]=temp%100/10;
// display[2]=temp%10;
} 展开
#include "delay.h"
#include "gpio.h"
#include "ds18b20.h"
u16 table1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
u16 table2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
u16 display[4];
void tem_deal(short temp);
int main(void)
{
u8 t;
stm32_SysClock72M(9);
delay_init(72);
Gpio_init();
while(1)
{
if(t==20)
{
t=0;
tem_deal(ds18b20_read());
// tem_deal(DS18B20_Get_Temp());
}
t++;
GPIOC->ODR=table1[0]; //λѡ
GPIOD->ODR=table2[display[0]]; //¶ÎÑ¡
delay_ms(1);
GPIOC->ODR=table1[1]; //λѡ
GPIOD->ODR=table2[display[1]]|0x80; //¶ÎÑ¡
delay_ms(1);
GPIOC->ODR=table1[2]; //λѡ
GPIOD->ODR=table2[display[2]]; //¶ÎÑ¡
delay_ms(1);
GPIOC->ODR=table1[3]; //λѡ
GPIOD->ODR=table2[display[3]]; //¶ÎÑ¡
delay_ms(1);
GPIOC->ODR=0x00;//ÏûÒþ
GPIOD->ODR=0x00;
}
}
void tem_deal(short temp)
{
float tm_value;
tm_value=temp;
temp=tm_value*0.625*10;
display[0]=temp/1000;
display[1]=temp%1000/100;
display[2]=temp%10000%100/10;//´Ë´¦¸Ä¾«È·¶È
display[3]=temp%10000%100%10;
// temp=temp*100;
// display[0]=temp/100;
// display[1]=temp%100/10;
// display[2]=temp%10;
} 展开
1个回答
2015-05-22
展开全部
每隔一段时间,读取一次温度,把读到的数通过IO口送出去显示
追问
貌似还是没有显示
追答
你先测试一下你的显示有没有正确,一是硬件连接,二是软件驱动。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询