完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
//------------------------------------------------------------------------------------
// F02x_Blinky.c //------------------------------------------------------------------------------------ // Copyright (C) 2007 Silicon Laboratories, Inc. // // AUTH: BW // DATE: 4 SEP 01 // // This program flashes the green LED on the C8051F020 target board about five times // a second using the interrupt handler for Timer3. // Target: C8051F02x // // Tool chain: KEIL Eval 'c' // //------------------------------------------------------------------------------------ // Includes //------------------------------------------------------------------------------------ #include #include #include #include #include #include //------------------------------------------------------------------------------------ // 16-bit SFR Definitions for 'F02x //------------------------------------------------------------------------------------ sfr16 DP = 0x82; // data pointer sfr16 TMR3RL = 0x92; // Timer3 reload value sfr16 TMR3 = 0x94; // Timer3 counter 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 sfr16 RCAP4 = 0xe4; // Timer4 capture/reload sfr16 T4 = 0xf4; // Timer4 sfr16 DAC0 = 0xd2; // DAC0 data sfr16 DAC1 = 0xd5; // DAC1 data //------------------------------------------------------------------------------------ // Global CONSTANTS //------------------------------------------------------------------------------------ #define BAUDRATE 9600 // Baud rate of UART in bps // 波特率必须是:9600 19200 38400 57600 115200 // 22118400频率太高,无法设置4800以下的波特率 // SYSTEMCLOCK = System clock frequency in Hz #define SYSTEMCLOCK 22118400 #define SYSCLK 2000000 // approximate SYSCLK frequency in Hz unsigned char xdata h[4096]; unsigned char a,b,a1,b1,d2; float c,d,d1,f,f1,g[10]; // green LED: '1' = ON; '0' = OFF ***it RS = P1^0; ***it Q2 = P1^1; ***it Q1 = P1^2; ***it SH = P1^3; unsigned long int i,j,k,m; unsigned char xdata high[2048]; unsigned char xdata low[2048]; //------------------------------------------------------------------------------------ // Function PROTOTYPES //------------------------------------------------------------------------------------ void CCD_PORT_Init (void); void OSCILLATOR_Init (void); void ADC0_Init (void); void delay (unsigned long int time); void UART0_Init (void); void PORT1_Init (void); //------------------------------------------------------------------------------------ // MAIN Routine //------------------------------------------------------------------------------------ void main (void) { // disable watchdog timer WDTCN = 0xde; WDTCN = 0xad; OSCILLATOR_Init (); // Initialize oscillator CCD_PORT_Init (); PORT1_Init (); ADC0_Init (); UART0_Init (); P1 = 0x0d; delay (15); RS=0; delay (15); RS=1; delay (15); P1=0x0b; //Q1=0; // Q2=1; delay (15); RS=0; delay (15); RS=1; delay (15); m = 0; while(1) { // for(m = 0; m < 10; m++) // { for(k = 0;k < 10; k++) { SH=0; delay (1); RS=0; delay (1); RS=1; delay (1); RS=0; delay (1); RS=1; delay (1); SH=1; delay (1); RS=0; delay (1); RS=1; delay (1); // Q1=1; //Q2=0; for(j = 0;j<20;j++) { P1=0x0d; delay (1); AD0BUSY = 1; while(AD0INT == 0); AD0BUSY = 0; AD0INT = 0; // high[m] = ADC0>>8; // low[m] = ADC0&0xff; RS=0; delay (1); RS=1; delay (1); // m++; P1=0x0b; delay (1); AD0BUSY = 1; while(AD0INT == 0); AD0BUSY = 0; AD0INT = 0; // high[m] = ADC0>>8; // low[m] = ADC0&0xff; RS=0; delay (1); RS=1; delay (1); // m++; } for(j = 0;j<1024;j++) { P1=0x0d; delay (1); AD0BUSY = 1; while(AD0INT == 0); AD0BUSY = 0; AD0INT = 0; high[m] = ADC0>>8; low[m] = ADC0&0x00ff; RS=0; delay (1); RS=1; delay (1); m++; P1=0x0b; delay (1); AD0BUSY = 1; while(AD0INT == 0); AD0BUSY = 0; AD0INT = 0; high[m] = ADC0>>8; low[m] = ADC0&0x00ff; RS=0; delay (1); RS=1; delay (1); m++; } for(j = 0;j<266;j++) { P1=0x0d; delay (1); AD0BUSY = 1; while(AD0INT == 0); AD0BUSY = 0; AD0INT = 0; // high[m] = ADC0>>8; // low[m] = ADC0&0xff; RS=0; delay (1); RS=1; delay (1); // m++; P1=0x0b; delay (1); AD0BUSY = 1; while(AD0INT == 0); AD0BUSY = 0; AD0INT = 0; // high[m] = ADC0>>8; // low[m] = ADC0&0xff; RS=0; delay (1); RS=1; delay (1); // m++; } SH = 0; m = 0; } for (i = 0; i<2048; i++) { SBUF0 = high[i]; while(TI0 == 0); TI0 = 0; SBUF0 = low[i]; while(TI0 == 0); TI0 = 0; } TI0 = 0; } } //------------------------------------------------------------------------------------ // PORT_Init //------------------------------------------------------------------------------------ // // Configure the Cros***ar and GPIO ports // void CCD_PORT_Init (void) { XBR2 = 0x40; // Enable cros***ar and weak pull-ups P1MDOUT = 0x0f; // enable P1.6 (LED) as push-pull output } //------------------------------------------------------------------------------------ // Timer3_Init //------------------------------------------------------------------------------------ // // Configure Timer3 to auto-reload and generate an interrupt at interval // specified by // void delay(unsigned long int time) { unsigned long int i; for(i = 0;i < time;i++) { _nop_(); } } void OSCILLATOR_Init (void) { int i; // delay counter OSCXCN = 0x67; // start external oscillator with // 22.1184MHz crystal for (i=0; i < 256; i++) ; // wait for oscillator to start while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle OSCICN = 0x88; // select external oscillator as SYSCLK // source and enable missing clock // detector } //----------------------------------------------------------------------------- void ADC0_Init (void) { REF0CN = 0x03; // Enable temp sensor, on-chip VREF, ADC0CF = 0xF8; // PGA gain = 1 (default) // and VREF output buffer AMX0CF = 0x00; // AIN inputs are single-ended (default) AMX0SL = 0x00; // Select AIN0.1 pin as ADC mux input // ADC0CF = 0x00; // ADC conversion clock = 2.5MHz ADC0CN = 0x80; // ADC0 disabled; normal tracking // mode; ADC0 conversions are initiated // right-justified// on overflow of Timer3; ADC0 data is } void UART0_Init (void) { long int value; value = 256 - (SYSTEMCLOCK/BAUDRATE)/16; SCON0 = 0x50; TMOD = 0x20; TH1 = value; // TH1 = 0x70; TR1 = 1; CKCON |= 0x10; PCON |= 0x80; } void PORT1_Init (void) { XBR0 = 0x04; XBR1 = 0x00; XBR2 = 0x40; // Enable cros***ar and weak pull-up // Enable UART1 P0MDOUT |= 0x01; // Set TX pin to push-pull } |
|
相关推荐
4个回答
|
|
|
|
|
|
求救,大神快来
|
|
|
|
你想多了
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
在只有一个电子负载仪的情况下,如何持续监控并记录太阳能充电板的全程充电电流?
1275 浏览 1 评论
5659 浏览 1 评论
9316 浏览 1 评论
8670 浏览 1 评论
1335 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 07:23 , Processed in 0.430441 second(s), Total 49, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号