⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mega16l_tc35.c

📁 基于51单片机/GSM模块西门子tc35i的远程控制源程序
💻 C
字号:
#include <mega16.h>
#include "LCD.h"
#include "DELAY.h"  
#include <USART.h> 
#include <ds18b20.h>
#include <1wire.h>
#include <stdlib.h>
#include <stdio.h>  

#asm
    .equ __w1_port=0x1b	//Port A.0
    .equ __w1_bit=0
#endasm

unsigned char rom_code[1][9];  

extern char rx_buffer[100];
extern unsigned char rx_counter;
bit rx_buffer_overflow;
/********************************************************************
函 数 名:USART_RX_ISR
入口参数:无
出口参数:无
建立日期:2008年5月6日
修改日期:
函数作用:串口接收中断
说    明:
********************************************************************/ 
interrupt [USART_RXC] void usart_rx_isr(void)
{
        char status,data;
        status=UCSRA;
        data=UDR;
        if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
        {
                rx_buffer[rx_counter]=data;
                if (++rx_counter == 100)
                {
                        rx_counter=0;
                        rx_buffer_overflow=1;
                };
        };
}

void main(void)
{   
    unsigned char mymessage1[]={"正在初始化"};
    unsigned char mymessage2[]={"初始化完毕"};
//    unsigned char mymessage3[]={"ERROR"};
    unsigned char mymessage4[]={"传输温度数据"}; 
    unsigned char mymessage5[]={"温度数据传输完毕"};              
    unsigned char temp_print[10];
    float temp=0;
    
    int i;
    
    DDRA = 0xFF;  
    PORTA = 0xFF; 
    Clr_CS();
    Clr_SID();
    Clr_SCLK();
    LCD_INIT();
    LCD_DISPLAY(mymessage1);    
    
    USART_INIT();
    DELAY_1MS(10);
//    i=w1_init();
    i= w1_search(0xF0, rom_code);
    ds18b20_init(&rom_code[0][0],0,0,DS18B20_9BIT_RES);
    DELAY_1S(1);
    #asm("sei")
    TC35_INIT();
    DELAY_1MS(10);        

    
    DELAY_1S(2);
    
    LCD_CLEAR();
    DELAY_1MS(10);
    LCD_DISPLAY(mymessage2);
    while (1)
    {     
          #asm("cli")
          temp=ds18b20_temperature(&rom_code[0][0]); 
          DELAY_100MS(1);
          #asm("sei")    
          ftoa(temp,5,temp_print);     //转换浮点数temp为字符串temp_print,其中第二位参数指定四舍五入保留小数位(最多五位)。    
          DELAY_1MS(10);
          LCD_CLEAR();
          DELAY_1MS(10);
          LCD_DISPLAY(temp_print);
          DELAY_1S(4);
          LCD_CLEAR();
          LCD_DISPLAY(mymessage4);
          DELAY_100MS(1); 
          TC35_SENDMESSAGE(temp_print);
          DELAY_100MS(1);
          LCD_CLEAR();
          LCD_DISPLAY(mymessage5);
          DELAY_1S(60);
    }
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -