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

📄 ad.c

📁 一个用adtlc2543采样电视波形,显示波形的51程序
💻 C
字号:

#include <c8051f200.h>                    // SFR declarations

//------------------------------------------------------------------------------------
// 16-bit SFR Definitions for 'F2xx
//------------------------------------------------------------------------------------

sfr16 DP       = 0x82;                    // data pointer
sfr16 ADC0     = 0xbe;                    // ADC0 data
sfr16 ADC0GT   = 0xc4;                    // ADC0 greater than window
sfr16 ADC0LT   = 0xc6;                    // ADC0 less than window
sfr16 RCAP2    = 0xca;                    // Timer2 capture/reload
sfr16 T2       = 0xcc;                    // Timer2

//------------------------------------------------------------------------------------
// Global CONSTANTS
//------------------------------------------------------------------------------------

sbit  RUN_LED = P2^5; 
sbit  audioclk = P2^4;
//------------------------------------------------------------------------------------
// Global VARIABLE
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Function PROTOTYPES
//------------------------------------------------------------------------------------
void Timer2_ISR (void);
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main (void) {
	unsigned char audiodata;
   // disable watchdog timer
   WDTCN = 0xde;
   WDTCN = 0xad;
   OSCICN |=2;//     : Internal Oscillator typical frequency is 8MHz.  		
   PRT2CF |= 0x30;                        // enable P2.5 (LED) as push-pull output//enable p2.4 as output
   PRT0CF = 0xff;                        // enable P0 as push-pull output
   PRT1CF |= 0x80;						//enable p1.7 as output
// Init Timer2 gto generate interrupts // at a 8kHz rate.
 // Configure Timer2 to auto-reload and generate an interrupt at interval
// specified by <T2_counts> using SYSCLK/12 as its time base.
   T2CON  = 0x00;                         // Stop Timer2; configure for auto-reload
   CKCON &= ~0x20;                        // T2M=0 (use SYSCLK/12 as timebase)
   RCAP2  = -83;//8000000/12/8000;                   // Init reload value
   T2     = 0xffff;                       // set to reload immediately
   ET2    = 1;                            // enable Timer2 interrupts
   TR2    = 1;                            // start Timer2
//AD init
	AMX0SL = 0x28;//0010 1000 select p1.0 for AD input
	ADC0CF = 0x62;//0110 0011 conversion clock is 1MHz, Gain is 4
	//Bits2-0: 000: Gain = 1/  001: Gain = 2/ 010: Gain = 4/ 011: Gain = 8/ 10x: Gain = 16/ 11x: Gain = 0.5
	ADC0CN = 0xcc;//1100 1100 
	REF0CN = 0x03;// select VDD as the refer Voltage

  EA = 1;								 // enable global interrupts
	audioclk = 0;
   while (1) {   
   		if(ADCINT==1)
		{
			ADCINT=0;
			audiodata=ADC0H;
			P0 =audiodata;
			audioclk=1;
			audioclk=0;
		}
   }
}


//------------------------------------------------------------------------------------
// Interrupt Service Routines
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
// Timer2_ISR
//------------------------------------------------------------------------------------
// This routine .
//
void Timer2_ISR (void) interrupt 5
{
   static unsigned int runc=0;
   TF2 = 0;                               // clear Timer2 overflow interrupt flag
   runc++;
   //run light: if is the lo then light, if is the ho then flash
   if (runc>=4000){
   		runc=0;
			RUN_LED = ~RUN_LED;
	}
}

 

⌨️ 快捷键说明

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