今天天气不错,早上看了下RXT-51的操作手册,下午写几行代码试了下,一次性通过。搞了个数码管显示温度的的。
#include
#include
unsigned int TEM() ;
void DS18B20int() ;
#define INIT 0
#define SEG_DIS 1
#define TEMP_RD 3
unsigned char Tab1[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0x90 , 0xBF };
unsigned char Tab2[]={0xc0,0xcf,0xa4,0x86,0x8b,0x92,0x90,0xc7,0x80,0x82 , 0x70};
unsigned char dis[]={0,0,0,0};
unsigned char SEG_dis_step ;
unsigned int count ;
unsigned char dot_pos ;
void init_sys( void ) _task_ 0 {
TMOD &= 0x0F; // init_tmr1
ET1 = 1 ;
TR1 = 1 ;
// 18B20 init
EA = 0 ;
DS18B20int() ; // init_18B20
EA = 1 ;
os_create_task(SEG_DIS) ;
os_create_task(TEMP_RD) ;
os_create_task(2) ;
os_delete_task( 0 ) ;
while(1) ;
}
void SEG_dis( void ) _task_ 1 {
while(1){
os_clear_signal(1) ;
switch( SEG_dis_step ){ // seg_dis
case 0 :
P1 = 0x7F ;
P0=Tab1[dis[0]];
SEG_dis_step++ ;
break ;
case 1 :
P1 = 0xBF ;
if(dot_pos == 2){
P0=Tab1[dis[1]] & ~0x80;
}
else{
P0=Tab1[dis[1]];
}
SEG_dis_step++ ;
break ;
case 2 :
P1 = 0xDF ;
P0=Tab2[dis[2]];
SEG_dis_step++ ;
break ;
case 3 :
P1 = 0xEF ;
P0=Tab2[dis[3]];
SEG_dis_step = 0 ;
break ;
default :
SEG_dis_step = 0;
}
os_wait ( K_SIG , 1, 0);
}
}
//--------------------------------------
//
//--------------------------------------
void cntadd( void ) _task_ 2 { // test
count = 0 ;
while(1){
count++ ;
dis[0]= count / 1000 ;
dis[1]= count % 1000 /100 ;
dis[2]= count % 100 /10 ;
dis[3]= count % 10 ;
os_wait ( K_TMO , 20 , 0);
}
}
//--------------------------------------
//
//--------------------------------------
void RD_18B20(void ) _task_ TEMP_RD{
while(1){
os_delete_task( 2 ) ;
EA = 0 ;
count = TEM();
EA = 1;
if( ( count & 0xFC00 ) == 0x00 ){ // temp > 0
count = (unsigned int)( count * 0.625 ) ;
dis[0]= count /100 ;
dis[1]= count % 100 /10 ;
dis[2]= count % 10 ;
dis[3] = 10 ;
dot_pos = 2 ;
}
else{ // temp < 0
count = ~count + 1 ;
count = count = (unsigned int)( count * 0.0625 ) ;
dis[0]= 10 ;
dis[1]= count % 100 /10 ;
dis[2]= count % 10 ;
dis[3] = 10 ;
dot_pos = 0xFF ;
}
os_wait ( K_TMO , 200 , 0);
}
}
//--------------------------------------
//
//--------------------------------------
void Tmr1(void) interrupt 3 {
TH1 = 0xA0 ;
TL1 = 0x00 ;
isr_send_signal(1) ;
}