请教各位朋友,
中颖单片机79H1612A单片机AD采集不到数据是怎么回事?
下面是我的程序:
#include <SH79F1612A.H>
#include <intrins.h>
#include <config.h>
typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned long uint32;
typedef signed long int32;
uint16 adval;
void delay(uint16 i)
{
while(i--);
}
void Init_IO()
{
P4M0 = 0x00;
P4M1 = 0x04;
P3M0 = 0x00;
P3M1 = 0x04;
}
uint16 Sample_AD(uint8 ch,uint8 smdt)
{
uint16 adval;
if(smdt==0)
{
ADT=Bin(00000000);
}
else
{
ADT =Bin(11101111);
}
switch(ch)
{
case 0: //AN0
ADCH=Bin(00000001);
ADCON=Bin(10000001);
break;
case 1: //AN1
ADCH=Bin(00000010);
ADCON=Bin(10000011);
break;
case 2: //AN2
ADCH=Bin(00000100);
ADCON=Bin(10000101);
break;
case 3: //AN3
ADCH=Bin(00001000);
ADCON=Bin(10000111);
break;
case 4: //AN4
ADCH=Bin(00010000);
ADCON=Bin(10001001);
break;
case 5: //AN5
ADCH=Bin(00100000);
ADCON=Bin(10001011);
break;
case 6: //AN6
ADCH=Bin(01000000);
ADCON=Bin(10001101);
break;
case 7: //AN7
ADCH=Bin(10000000);
ADCON=Bin(10001111);
break;
default:
break;
}
while((ADCON&Bin(01000000))==0)
{
_nop_();
}
adval=ADDH*4+ADDL;
ADCON=Bin(00000000);
return(adval);
}
/*********************************************************************************************
** oˉêyÃû3Æ: main
** oˉêyÃèêö: Ö÷oˉêy
** êäèë2Îêy: ÎT
** êä3ö2Îêy: ÎT
*********************************************************************************************/
void main()
{
P4_2 = 1;
Init_IO();
//Init_AD();
while(1)
{
Sample_AD(1,1);
//GetADCH_8();
//GetADCL_8();
//GetADC_16();
if(adval >1001001110)
{
P4_2 = 0;
P3_2 = 0;
delay(50000);
P3_2 = 1;
delay(50000);
}
else
{
P4_2 = 1;
}
}
}
|