?? body_test.c
字號:
// Includes
//-----------------------------------------------------------------------------
#include <c8051f020.h>
#define uchar unsigned char
#define uint unsigned int
#include <Lcd1602.h>
#include <Key.h>
#include <DS18B20_Driver.h>
//uchar Times;
// Function Library
//-----------------------------------------------------------------------------
void SYSTEM_Init (void);
void PORT_Init (void);
void Temperature_Display(uint Temp);
//-----------------------------------------------------------------------------
extern void Timer1_Init(void);
extern void Timer3_Init (int counts);
extern uchar Puls_Counter(void);
extern void Display_Pusle(uchar times);
//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
void main (void)
{
SYSTEM_Init ();
PORT_Init ();
Lcd1602_Ini();
Timer1_Init();
Timer3_Init (36864);// counts = 36864 T = 0.02s
DS18B20_Init();
EA = 1;
while(1)
{
Lcd1602_Clear_Line(1);
Lcd1602_Write_String(1,1," Press any key!");
while(Key_Word()==0xff);
Display_Pusle(Puls_Counter());
}
}
void Temperature_Display(uint Temp)
{
uint t,i; uint a[5];
t = Temp*6.25;
a[0] = t/1000;
a[1] = (t-a[0]*1000)/100;
a[2] = '.'-'0';
a[3] = (t-a[0]*1000-a[1]*100)/10;
a[4] = (t-a[0]*1000-a[1]*100-a[3]*10);
//Lcd1602_Clear_Line(2);
Lcd1602_Write_String(2,9,"T:");
for(i=0;i<5;i++){ Lcd1602_Write_char(a[i]+'0'); }
Lcd1602_Write_char('C');
}
// SYSTEM_Init
void SYSTEM_Init (void)
{
int i;
WDTCN = 0xde; // disable watchdog timer
WDTCN = 0xad;
//OSCICN = 0x17; // 選用內部振蕩器 16MHZ
// delay counter
OSCXCN = 0x67; // start external oscillator with
// 22.1184MHz crystal
for (i=0; i < 256; i++) ; // wait for XTLVLD to stabilize
while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
OSCICN = 0x88; // select external oscillator as SYSCLK
// source and enable missing clock
// detector
}
//-----------------------------------------------------------------------------
// PORT_Init
void PORT_Init (void)
{
XBR0 |= 0x00;
XBR1 |= 0x08; // Enable Counter1
XBR2 |= 0x40; // Enable crossbar and weak pull-ups
P0MDOUT |= 0x00; // 鍵盤P1口配置位漏極方式
P74OUT |= 0xff; // 顯示P4控制口,P5數據口,均配置為推挽方式
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -