coneol.c ( File view )

  • By 浩哥 2014-11-09
  • View(s):80
  • Download(s):0
  • Point(s): 1
			#include<intrins.h>				   //
#include<absacc.h>				   //
#include<string.h>				   //
#include<stdio.h>				   //

#define uchar unsigned char		   //
#define uint unsigned int		   //
#define ulong unsigned long		   //

sbit ACIN = P3^3;				       //交流同步信号外部中断1输入
//sbit PF   = P3^7;				       //升压脉冲输出,频率为25KHz左右

sbit ledR  =P3^0;				   //	没用
sbit ledG  =P3^1;				   //

sbit led3 =P1^3;				   //蓝光输出
sbit led2 =P1^4;				   //绿光输出
sbit led1 =P1^5;				   //红光输出

sbit bit8 =P2^5;				   //	  S8
sbit bit7 =P2^6;				   //	  S7
sbit bit6 =P2^7;				   //	  S6
sbit bit5 =P3^5;				   //	  S5
sbit bit4 =P3^2;				   //	  S4
sbit bit3 =P2^3;				   //	  S3
sbit bit2 =P1^6;				   //	  S2
sbit bit1 =P1^7;				   //	  S1

uint kk,kk1,ok;
uint speed;	

uchar cstar,cok;			         	  //  	
uint u;
//uchar u;
uint c1;
uchar a;


void init()							  //初始化
{

	 TMOD=0X11;						  //	T0、T1用作16位定时
	 AUXR=0Xc0;						  //	1T
	 TH0=0x8a;						  //
	 TL0=0xd0;						  //
	 ET0=1;							  //
	 TH1=0x15;						 //	TH1=0x63;
	 TL1=0xa0;						 //	TL1=0xc0;
	 ET1=0;
	 EA=0;							  //
//	 REN=1;							  //
//	 SM0=1;							  //
//	 SM1=1;							  //
	 TR0=1;							  //
	 TF0=0;
//	 TF1=0;
//	 TR1=1;							  //
	 IT1=1;							  //外部中断1是下降沿触发中断
	 EX1=1;
     P3M1=0X00;	//  P3M1=0X3c;						  //		

	 EA=1;

}


void int1() interrupt 2					//外部AC交流下降沿中断
{
 
  cok=1; 
  a=0; 
  kk++;
  if (kk>1)  ledR=0;
  if (kk==100) 		
  {

   ledR=1;
   kk=0;
   
}
  EX1=0;     //关外部中断1
  TH0=0x15;						  //
  TL0=0xa0;						  //
  TR0=1;		//开定时0,定时17ms后再打开外部中断,在此期间内所有输入不能进来,起到抗干扰作用。		  

}


void time0() interrupt 1			//		
{
 

 a++;
if (a==2)
{
	 
//  ledG=!ledG;
  EX1=1;   //定时17ms后开外部中断1,如果检测到交流波的第一个下降沿就将同步信号置1,同时重启17ms的定时。
  kk1++;
//  if (kk1>1)  ledG=0;
  if (kk1==100) 		
  {

//   ledG=1;
   kk1=0;
   
}
   
//  ledG=!ledG;	   		  
  a=0;
  TH0=0x15;						  //
  TL0=0xa0;						  //
 
} 

}
void main()
{
	
		  //
	uchar pwm_sw;		  //
	uint b;			  //
//	uchar b;			  //
	uint speed_c;		  //
	bit pwm_down;		  //
	bit pwm_up;			  //

	led1=1;						  //  因为有反相,所以上电时要把灯灭了。
	led2=1;						  //  因为有反相,所以上电时要把灯灭了。
	led3=1;						  //  因为有反相,所以上电时要把灯灭了。
	init();

//**********************************************************************************************
//	 	ok=1;
//		while  (ok);
		u=0;
		cok=0;	
		pwm_up=0;
		pwm_down=0;
		cstar=0;
//	    speed=10;
		speed_c=0;
		ledG=0;
	while(1)
	{
  
/*			
//			if(cok==1) {
cok=0;speed_c++;
}
//			speed_c++;
//			if(speed_c1>2) {
speed_c++;speed_c1=0;
}

		  //*********************
//			if(speed_c>speed)
//			ledR=!ledR;
//			if((speed_c>=23)&(cok==1))			   //1.3KHz频率时,55刚好是1分钟一个大循环。600Hz频率时,25刚好是1分钟一个大循环
//			if(cok==1) {
cok=0;speed_c++;
}
*/
 			if(cok==1) {
cok=0;speed_c++;
}
//		    speed_c++;
 			if((pwm_sw==0)&(u<4)) speed=40;
 			else
 			if((pwm_sw==4)&(u<2)) speed=20;
			else
 			speed=0;

			if(speed_c>speed)					  //
//         if(cok==1)
		 {

//			cok=0;

			{

			    speed_c=0;
			 	u++;
//				if(u==255)
				if(u==800)
				{

					u=0; 
					pwm_sw++;
					if(pwm_sw>5)			  //总共是6段一个循环
					{

						pwm_sw=0;
					
}
				
}
			 
}
		   
}
		  //***********************	
		  

		  			 
//			for(b=255;b>0;b--)
			for(b=800;b>0;b--)
			{

			
				if(b<u)
				{

					pwm_up=1;
					pwm_down=0;
				 
}
			    else
				{

					pwm_up=0;
					pwm_down=1;
				
}




//				for(wait=0;wait<5;wait++);//		for(wait=0;wait<5;wait++);		 //PWM频率600Hz左右
				switch (pwm_sw)
				{

  

				    case 1:	//绿亮红渐暗
					{

						led2=0;
						led3=1;
						if(pwm_down==1)	led1=0;	//0为亮,1为灭 
						else 			led1=1; 
					
}
					break;
				    case 2:	//绿亮蓝渐亮	OK
					{

						led2=0;
						led1=1;
						if(pwm_up==1)	led3=0;			      
						else 			led3=1;	
//											
					
}
					break;
					case 3:	//蓝亮绿渐暗
					{

						led3=0;
						led1=1;
						if(pwm_down==1)	led2=0;
						else 			led2=1;
					
}
					break;
					case 4:	//蓝亮红渐亮		*********************************************************
					{

						led3=0;
						led2=1;
						if(pwm_up==1)	 led1=0;	  
						else 			 led1=1;
					
}
					break;		  
					case 5:	//红亮蓝渐暗	
					{

						led1=0;
						led2=1;
						if(pwm_down==1)	led3=0;	  
						else 			led3=1;
					
}
					break;		   
					case 0:	//红亮绿渐亮		 ***************************************************************
					{

						led1=0;
						led3=1;
						if(pwm_up==1)	 led2=0;	  
						else 			 led2=1;	
//						for(wait=0;wait<60;wait++);							
					
}
					break;		   

				
}
			
}
		
}

	

}			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
coneol.c4.82 kB09-11-14 22:59
...
Sponsored links

coneol.c (1.75 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D