📄 330cp0.c
字号:
//将J4的1脚与J5的2脚用短路线短接.
/*------------------------------------------------------------------------
按下S4键小灯就亮一下,CP-端拉低。
功能:比较器正端输入外部电压+2.5V,负端接到按键S4上.当CP+>CP-小灯亮即当按下S4键LED亮.
--------------------------------------------------------------------------*/
#include "C8051F350.h"
#include <intrins.h>
void CPT0_ISR (void);
//sbit S4=P1^5;
sbit LED=P0^1;
unsigned int i;
void Comparator_Init(void)
{
int i = 0;
CPT0CN = 0x8F;
for (i = 0; i < 35; i++); // Wait 10us for initialization
CPT0CN &= ~0x30;
CPT0MX = 0x61;
CPT0MD = 0x22;
}
//This is the port Init setup:
void PORT_Init(void)
{
P1MDIN = 0xff;
// P0.0analog input
P1SKIP = 0xff;
// P1.5analog input
// 跳过P1^5引脚
P0MDOUT = 0x02;
LED=0; // enable P1.0 outputs as push pull
XBR1 = 0x40;// enable crossbar 禁止
}
void main( void )
{
PCA0MD &= ~0x40; // disable watchdog
PORT_Init();
Comparator_Init();
LED=0;
EA=1;
EIE1|=0X20;
}
void sleep_ms(unsigned int count)
{
unsigned char ii,jj;
for(ii=0;ii<count;ii++)
{
for(jj=0;jj<250;jj++)
_nop_();
}
}
void CPT0_ISR (void) interrupt 12
{
CPT0CN &=~ 0x30; /*清中断标志位*/
{for(i=0;i<200;i++);
{ LED=1; /*有键按下*/
sleep_ms(200);
sleep_ms(200);
sleep_ms(200);
LED=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -