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

📄 wendu.c

📁 程序是C8051F020的内部测试温度的程序
💻 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;

}

 

⌨️ 快捷键说明

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