#include<reg51.h>
#include<stdio.h>
#include<math.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define ADC0832CH0 channel;
sbit clk_adc0832=P3^6;
sbit cs_adc0832=P2^0;
sbit di_adc0832=P3^7;
sbit do_adc0832=P3^7;
sbit LED0_CS=P1^0;
sbit LED1_CS=P1^1;
sbit LED2_CS=P1^2;
sbit LED3_CS=P1^3;
sbit adarm=P2^2;
uchar code table[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90, 0xff};
uchar ch;
void tkey(void);
unsigned runADC0832(bit);
void Delayms(uint x);
void Update_LED();
void LED_analyze();
void main()
{
P0=0XFF;
P1=0XFF;
P2=0XFF;
P3=0XFF;
Uart_Init();
TH0=0x3C;
TL0=0xAF;
ET0=1;
EA=1;
TR0=1;
nCounter=0;
Change_Flag=0;
while(1)
{
void tkey(void);
runADC0832();
if(Change_Flag==1)
{ Update_LED();
if(ch>9999)
ch=0;
printf("counter refreshed %d \n",ch);
}
delay();
按键为P1.0---P1.7
void Tkey(void)
{
uchar readkey;
uchar x_temp,y_temp;
P1=0x0f;
x_temp=P1&0x0f;
if(x_temp==0x0f) goto keyout;
P1=0xf0;
y_temp=P1&0xf0;
readkey=x_temp|y_temp;
readkey=~readkey;
switch(readkey)
{
case 0x11:key=0; break;
case 0x21:key=1; break;
case 0x41:key=2; break;
case 0x81:key=3; break;
case 0x12:key=4; break;
case 0x22:key=5; break;
case 0x42:key=6; break;
case 0x82:key=7; break;
case 0x14:key=8; break;
case 0x24:key=9; break;
case 0x44:key=10;break;
case 0x84:key=11;break;
case 0x18:key=12;break;
case 0x28:key=13;break;
case 0x48:key=14;break;
case 0x88:key=15;break;
default: key=16;break;
}
keyout:_nop_();
}
unsigned runADC0832(void)
{
uchar i=0;
uchar j;
uint dat=0;
uchar ndat=0;
if(channel==0)channel=2;
if(channel==1)channel=3;
ADDI=1;
_nop_();
_nop_();
ADCS=0;
_nop_();
_nop_();
ADCLK=1;
_nop_();
_nop_();
ADCLK=0;
_nop_();
_nop_();
ADCLK=1;
ADDI=channel&0x1;
_nop_();
_nop_();
ADCLK=0;
_nop_();
_nop_();
ADCLK=1;
ADDI=(channel>>1)&0x1;
_nop_();
_nop_();
ADCLK=0;
ADDI=1;
_nop_();
_nop_();
dat=0;
for(i=0;i<8;i++)
{
dat|=ADDO;
ADCLK=1;
_nop_();
_nop_();
ADCLK=0;
_nop_();
_nop_();
dat<<=1;
if(i==7)dat|=ADDO;
}
链接:https://pan.baidu.com/s/1FjVldGy_ONspJA4K6R_lrw 提取码:a917
|