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

📄 main.c

📁 STC51系列的源码
💻 C
字号:
/********************************************************************************/
/* filename : MAIN.c                                                            */
/* created  : xillinx                                                           */
/* descript : 系统的C函数入口                                                   */
/********************************************************************************/
#include "../CPU/CPU.h"
#include "../CFG/CFG.h"
#include "../UART/UART.h"
#include "../LED/LED.h"
#include "../SEG7/SEG7.h"
#include "../HC595/HC595.h"
#include "../TC1602A/TC1602A.h"
#include "../DS18B20/DS18B20.h"

unsigned int  system_timer=0x00;    //* 这是系统需要的定时器变量

/********************************************************************************/
/* funname : MAIN_ds18b20_hook()                                                */
/* created : xillinx                                                            */
/* time    : 2008-08-06                                                         */
/* descript: DS18B20启动转换HOOK函数                                            */
/********************************************************************************/
void MAIN_ds18b20_hook(void)
{   DS18B20_mflag=0x1;
}

/********************************************************************************/
/* funname : MAIN_proc_ds18b20()                                                */
/* created : xillinx                                                            */
/* time    : 2008-08-06                                                         */
/* descript: DS18B20调试输出                                                    */
/********************************************************************************/
void MAIN_proc_ds18b20(void)
{   unsigned char flag;
    unsigned char dt;
    char buffer[0x20];
    int  mdata;
    int  lo;
    int  hi;

    if(DS18B20_mflag==0x0)
    {   return;
    }
    DS18B20_mflag=0x0;
    mdata=(int)DSB20_read_temperature();
    DSB20_delay_100_us();
    DSB20_start_convert();
	if(mdata<0x0)
    {  flag=0x1;
       mdata=-mdata;
    }
    else
    {  flag=0x0;
    }
    dt=mdata&0xF;
    hi=mdata>>0x4;
    lo=0x0;
    if(dt&0x8)
    {  lo+=5000;
    }
    if(dt&0x4)
    {  lo+=2500;
    }
    if(dt&0x2)
    {  lo+=1250;
    }
    if(dt&0x1)
    {  lo+=625;
    }
    
    if(flag)
    {  sprintf(buffer,"-%d.%d",hi,lo);
    }
    else
    {  sprintf(buffer,"%d.%d",hi,lo);
    }
    LCDT_LED_clear();
    LCDT_print_string(0x0,0x0,"  temperature  ");     /* 测试点阵LCD */
    LCDT_print_string(0x2,0x1,buffer);
    return;
}

/********************************************************************************/
/* fun_name : MAIN_interrupt_hook_process()                                     */
/* version  : v1.00                                                             */
/* created  : xillinx                                                           */
/* descript : 定时器钩子函数的处理,如果需要使用这些函数,需要重新挂接,如果不需要 */
/*  不需要做任何事情                                                            */
/********************************************************************************/
void MAIN_interrupt_hook_process (void)
{   CPU_001_tick_process = CPU_interrupt_proc_null; //* 定时器钩子函数的缺省处理,如果需要使用这些函数,需要重新挂接
    CPU_002_tick_process = CPU_interrupt_proc_null;
    CPU_004_tick_process = CPU_interrupt_proc_null;
    CPU_008_tick_process = CPU_interrupt_proc_null;
    CPU_010_tick_process = CPU_interrupt_proc_null;
    CPU_020_tick_process = CPU_interrupt_proc_null;
    CPU_040_tick_process = CPU_interrupt_proc_null;
    CPU_080_tick_process = CPU_interrupt_proc_null;
    CPU_100_tick_process = CPU_interrupt_proc_null;
    CPU_200_tick_process = CPU_interrupt_proc_null;
    CPU_400_tick_process = CPU_interrupt_proc_null;
    CPU_extern_0_process = CPU_interrupt_proc_null;
    CPU_extern_1_process = CPU_interrupt_proc_null;
    CPU_timer_02_process = CPU_interrupt_proc_null;
                                                    //* 重新挂接HOOK函数
    CPU_001_tick_process = HC595_refresh;           //* 2MS
    CPU_080_tick_process = LED_refresh;             //* 128x2=256MS
    CPU_400_tick_process = MAIN_ds18b20_hook;       //* 2秒钟启动一次转换
}

/********************************************************************************/
/* function : main()                                                            */
/* recension: xillinx                                                           */
/* descript : 主函数入口                                                        */
/********************************************************************************/
void main (void)
{   unsigned int delax=0x8000;
    while(delax--)
    {   ;
    }
    LCDT_initialize();
    UART_buffer_initilize();
    MAIN_interrupt_hook_process();      //* CPU的挂接函数处理
    CPU_source_initialize();            //* 控制CPU的资源
    SEG7_clear_screen();
    SEG7_printf_ascii("1234.567");      //* 测试七段数码管
    UART_printf("融益通讯学习板\r\n");  //* 测试UART串口
    LCDT_print_string(0x0,0x0,"rongyitong tech");     /* 测试点阵LCD */
    LCDT_print_string(0x0,0x1,"cchhww11@tom.com");
    DSB20_initialize();
    while(1) 
    {   MAIN_proc_ds18b20();
    }
}

⌨️ 快捷键说明

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