显示为洛基亚5110
单片机源程序如下:
- #include "delay.h"
- #include "LCD5110.h"
- #include "ds18b20.h"
- #include "sys.h"
- #include "timer.h"
- #include "exti.h"
- // vu8 i = 0;
- u8 str[20];
- s16 temperature ; //温度
- int main(void)
- {
- RCC_Configuration(); //系统时钟配置
- GPIO_Configuration();
- delay_init() ;
- NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
-
- TIM3_Int_Init(4999,7199);//10Khz的计数频率,计数到5000为500ms
- /*
- // 配置外部中断
- KEY_Init();
- EXTIX_Init();
- */
- SPI2_Config();
- DMA_SPI_Config();
-
- LCD_CLK_H();
- LCD_VCC_H();
- LCD_GND_L();
- LCD_BGL_L(); //背光灯开启
-
- delay_ms(10); //等待
- LCD_Init(); //初始化液晶
- LCD_Clear(); //清屏
-
- while(DS18B20_Init()) //DS18B20初始化
- {
- LCD_Write_EnStr(0,0,"DS18B20 Error");
- }
- LCD_Write_EnStr(2,2,"DS18B20 OK");
- delay_ms(1000);
- delay_ms(1000);
- LCD_Write_EnStr(0,0,"*************");
- LCD_Write_EnStr(0,1," The current ");
- LCD_Write_EnStr(0,2," temperature");
- LCD_Write_EnStr(6,3,"is");
- LCD_Write_EnStr(0,5,"*************");
-
- while(1)
- {
- if(temperature<0)
- {
- LCD_Write_EnStr(2,4,"-"); //显示负号
- temperature=-temperature; //转为正数
- }else LCD_Write_EnStr(0,4," "); //去掉负号
- LCD_Write_EnStr(4,4,str);
- }
- }
- //定时器3中断服务程序
- //每500ms读取一次温度
- void TIM3_IRQHandler(void) //TIM3中断
- {
-
- if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检查TIM3更新中断发生与否
- {
- temperature = DS18B20_Get_Temp(); //读取温度
- num_to_str( temperature,str); //将温度转换为ASC值
- TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //清除TIMx更新中断标志
- }
- }
- /*
- void EXTI3_IRQHandler(void)
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
测温.rar
(308.57 KB, 下载次数: 77)
|