?? wendu.c
字號:
#include<stdio.h>
#include<c8051f020.h>
sfr TMR3RL =0x92;
sfr TMR3=0x94;
sfr16 ADC0=0xbe;
#define SYSCLK 221184
#define SAMPLE_RATE 10000
sbit P0_0=P0^0;
sbit P0_1=P0^1;
int out;
int out1;
code int serach[]={0xfd,0x61,0xdb,0xf3,0x67,0xf7,0xe1,0xff,0xf7,0x12};
void SYSCLK_Init (void);
//void time1_init(); //
void ADC0_Init (void);
void TIMER3_Init (int counts);
void ADC_ISR(void);
int ledshow(int k,int j);
long re;
void main(void)
{
long temp;
int temp_int;
int temp_frac;
WDTCN=0xde;
WDTCN=0xad;
TMOD = 0x10;
CKCON|=0x10;
PCON|=0x80;
TMR3CN = 0x02;
SYSCLK_Init();
P0MDOUT = 0xFF;
P2MDOUT = 0xFF;
XBR2 = 0x40;
TIMER3_Init(SYSCLK/SAMPLE_RATE);
ADC0_Init();
AD0EN=1;
re=0L;
IE = 0x80;
EA=1;
while(1) {
temp=re;
temp-=0xa381;
temp*=0x01a9;
temp*=100;
temp=temp>>16;
temp_int =temp/100;
temp_frac =temp-(100*temp_int);
P2=ledshow(temp_int,temp_frac);
}
}
void SYSCLK_Init(void)
{
int i;
OSCXCN = 0x67;
for (i=0;i< 256;i++);
while(!(OSCXCN & 0x80));
OSCXCN =0x88;}
void ADC0_Init(void)
{
ADC0CN=0x08;
REF0CN=0x07;
AMX0SL=0x08;
EIE2|=0x02;
}
void TIMER3_Init(int counts)
{
TMR3CN=0x02;
TMR3RL=-counts;
TMR3=0xffff;
EIE2 =0x01;
TMR3CN|=0x04;
}
void ADC_ISR(void) interrupt 15
{
static unsigned int_dec=256;
static long ac=0L;
AD0INT= 0;
ac+=ADC0;
int_dec--;
if(int_dec==0){
int_dec=256;
re=ac>>4;
ac=0L;
}
}
int ledshow(int j,int k)
{
switch(j)
{
case 0:out=serach[0];
case 1:out=serach[1];
case 2:out=serach[2];
case 3:out=serach[3];
case 4:out=serach[4];
case 5:out=serach[5];
case 6:out=serach[6];
case 7:out=serach[7];
case 8:out=serach[8];
case 9:out=serach[9];
default:break;
}
switch(k)
{
case 0:out1=serach[0];
case 1:out1=serach[1];
case 2:out1=serach[2];
case 3:out1=serach[3];
case 4:out1=serach[4];
case 5:out1=serach[5];
case 6:out1=serach[6];
case 7:out1=serach[7];
case 8:out1=serach[8];
case 9:out1=serach[9];
default:break;
}
P0_0=0;
P0_1=1;
return out1;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -