51单片机 运算能力 测试
时间:11-19
来源:互联网
点击:
timer.c:
#include "def.h"#ifdef TIMER// 计时变量: uint t_msec=0; // millisecond counter.uchar t_sec=0; // second counter.float t_cur=0.0; // second & millisecond.#define MODE1T //Timer clock mode, comment this line is 12T mode, uncomment is 1T mode#define FOSC 11059253L // 11.0592 MHz#ifdef MODE1T#define T1MS (65536-FOSC/1000) //1ms timer calculation method in 1T mode#else#define T1MS (65536-FOSC/12/1000) //1ms timer calculation method in 12T mode#endifvoid tm0_init(void) //50毫秒@11.0592MHz{#ifdef MODE1TAUXR |= 0x80;#elseAUXR &= 0x7F; // 最高位置0 //定时器时钟12T模式#endifTMOD |= 0x01; // 最低位置1 // 16位定时器EA = 1;ET0 = 1;TL0 = T1MS; //设置定时初值TH0 = T1MS >> 8; //设置定时初值TR0 = 1; //定时器0开始计时}//定时器0中断服务程序/* Timer0 interrupt routine */void tm0_isr() interrupt 1 // using 1{TL0 = T1MS; //reload timer0 low byteTH0 = T1MS >> 8; //reload timer0 high byte++t_msec;t_cur += 0.001;if (t_msec == 1000) { //1ms * 1000 -> 1st_msec = 0; //reset millisecond counter++t_sec; // second counter.P0 ^= 0x0f; // lighting... ...}}void restart(void){t_msec=0;t_sec=0;t_cur=0.0;tm0_init();}#endif // TIMER
UART.c:
#include "def.h"#ifdef UARTxdata char buffer[32]; // 全局变量.//串口初始化 晶振为 11.0592M 方式 1 波特率 300-57600 void UART_init(unsigned char BaudRate) { unsigned char THTL; switch (BaudRate) { case 1: THTL = 64; break; //波特率 300 case 2: THTL = 160; break; //600 case 3: THTL = 208; break; //1200 case 4: THTL = 232; break; //2400 case 5: THTL = 244; break; //4800 case 6: THTL = 250; break; //9600 case 7: THTL = 253; break; //19200 case 8: THTL = 255; break; //57600 default: THTL = 250; } SCON = 0x50; //串口方式 1 ,8位 波特率可变 允许接收 TMOD = 0x20; //定时器1定时方式2 TCON = 0x40; //设定时器 1 开始计数 PCON = 0x80; //波特率加倍控制,SMOD 位 TH1 = THTL; TL1 = THTL; RI = 0; //清收发标志 TI = 0; // 发送TR1 = 1; //启动定时器 }void send_data(char OutData) //向串口输出一个字符(非中断方式) { SBUF = OutData; //输出字符 while(!TI); //空语句判断字符是否发完 TI = 0; //清 TI }void send_str(char* str) // 串口发送字符串{while(*str) send_data(*str++);}// #define UARTOUT(inum) ComOutChar((uchar)inum);// ComOutChar((uchar)inum>>8);ComOutChar((uchar)inum&0xff); #endif // UART
51单片机运算能 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)