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

📄 function.c

📁 LED显示面板
💻 C
📖 第 1 页 / 共 5 页
字号:
#include "main.h"


unsigned int addr_led7[6] = {0x2100,0x2900,0x2500,0x2d00,0x2300,0x2b00};
unsigned char led7_data[18]= {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x86,0x88,0xff,0xc8,0x8e,0x86,0xaf,0xa3};
SHD_LED  pannel_led[48];
unsigned char key[8]={0xa5,0xa5,0xa5,0xa5,0xa5,0xa5,0xa5,0xa5};
extern unsigned char mode_flag ;
extern unsigned char T1,channel;
extern VCI_CAN_OBJ rece_data[20],sendmsg;
extern unsigned char soundoff[48];
unsigned char out_state;
 VCI_CAN_OBJ sendmsg;
 extern long id4;
 
unsigned int current_jisuan(float fullscal,unsigned int current)
{
 float result,temp,k0;
 unsigned int tt;
 CLI();
 WDR();
 temp = (float)(current/100.0);               //电流测量值计算
 
 k0 = fullscal/16.0;                 //斜率计算
 
 result = k0*temp -4*k0;             //显示值计算

 tt = (unsigned int )(result*100); 
 SEI();
 
 return tt;
}

void turn_display(unsigned char channel,unsigned char point_flag,unsigned int data)
{
unsigned char t1,t2,t3,t4;
unsigned int t5;
if( pannel_led[channel].up_down==0xa5)
{
 if( pannel_led[channel].state==0x5a)
   {
   PORTD |= 0x01;
   PORTD &= 0x7f;
   }
  else if(pannel_led[channel].state==0)
  {
  PORTD&=0x7e;
    }
  else if(pannel_led[channel].state==0xa5)
 {
 PORTD |= 0x03;
 PORTD &= 0x7f;
   }	
  }
 else if(pannel_led[channel].up_down==0x5a) 
 {
   if( pannel_led[channel].state==0x5a)
   {
   PORTD |= 0x02;
    PORTD &= 0x7f;
   }
  else if(pannel_led[channel].state==0)
  {
  PORTD&=0xfd;
    }
  else if(pannel_led[channel].state==0xa5)
 {
 PORTD |= 0x03;
  PORTD &= 0x7f;
 }	
  }
 

t1 = channel/10;
t2 = channel%10;
if(!t1)
led7_display(12,0,0,1);
else
led7_display(t1,0,0,1);

led7_display(t2,1,0,1);
if(pannel_led[channel].state!=0xa5)
{WDR();
  if(channel<36)
  {    
    if(point_flag == 1)
    {
      CLI();
	  WDR();
      t5 = data;
      t1 = t5/1000;
      t2 = (t5%1000)/100;
      t3 = ((t5%1000)%100)/10;
      t4 = ((t5%1000)%100)%10;
      if(t1)
	  {
  	   led7_display(t1,2,0,1);
  	    led7_display(t2,3,0,1);
   		led7_display(t3,4,1,1);
   		led7_display(t4,5,0,1);
 				 }
		else 
		{
  		  if(t2)
   		  {
   		  led7_display(12,2,0,1);                // t1=0
    	  led7_display(t2,3,0,1);
    	  led7_display(t3,4,1,1);
    	  led7_display(t4,5,0,1);
    	  }
  		  else
    	    {                                     // t1=0,t2=0
	   		if(t3)
	    	 {
        	  led7_display(12,2,0,1);               //  t3!=0
         	  led7_display(12,3,0,1);
         	  led7_display(t3,4,1,1);
         	  led7_display(t4,5,0,1);
               }
	  	   else
	        {                               //t1=0,t2=0,t3=0
		       if(t4)  
			   {
			   led7_display(12,2,0,1);                 
               led7_display(12,3,0,1);
               led7_display(0,4,1,1);
               led7_display(t4,5,0,1);
			    } 
			  else
			   {
			   led7_display(12,2,0,1);        // t1=0,t2=0,t3=0,t4=0           
               led7_display(12,3,0,1);
               led7_display(12,4,0,1);
               led7_display(0,5,0,1);
				} 
		     }		   
	     }	
     }

SEI();
}

else if(point_flag == 2)
    {
	CLI();
	WDR();
	t5 = data;
	t1 = t5/1000;
	t2 = (t5%1000)/100;
	t3 = ((t5%1000)%100)/10;
	t4 = ((t5%1000)%100)%10;
	if(t1)
	{
   	 led7_display(t1,2,0,1);
   	 led7_display(t2,3,1,1);
  	  led7_display(t3,4,0,1);
  	   led7_display(t4,5,0,1);
 	    }
	else 
	{
  	 	  if(t2)
   		  {
    	  led7_display(12,2,0,1);               //  t1=0
    	  led7_display(t2,3,1,1);
    	  led7_display(t3,4,0,1);
    	  led7_display(t4,5,0,1);
   		   }
  		    else
     		 {                                     // t1=0,t2=0
	   		 if(t3)
	    	  {
         	   led7_display(12,2,0,1);              //   t3!=0
        	   led7_display(t2,3,1,1);
         	   led7_display(t3,4,0,1);
         	   led7_display(t4,5,0,1);
               }
	 		   else
	      	   	   {                              // t1=0,t2=0,t3=0
		   		    if(t4)  
					{
					  led7_display(12,2,0,1);                 
          			  led7_display(t2,3,1,1);
          			  led7_display(0,4,0,1);
          			  led7_display(t4,5,0,1);
					    } 
				    else
					 {
			 		 led7_display(12,2,0,1);        // t1=0,t2=0,t3=0,t4=0           
            		 led7_display(12,3,0,1);
         		     led7_display(12,4,0,1);
                     led7_display(0,5,0,1);
				     } 
		           }		   
	            }	
              }
     SEI();
    }
   }
   else  if(data==0x5a)
 {
 WDR();
 led7_display(0,2,0,1);
 led7_display(13,3,0,1);
 led7_display(12,4,0,1);
 led7_display(12,5,0,1);
     }
 else if(data== 0xa5)
 {WDR();
 led7_display(0,2,0,1);
 led7_display(14,3,0,1);
 led7_display(14,4,0,1);
 led7_display(12,5,0,1);
      }
    }	 
 
 else
 {WDR();
 led7_display(15,2,0,1);
 led7_display(17,3,0,1);
 led7_display(16,4,0,1);
 led7_display(16,5,0,1);
   }
}

void delay_1us(void)
     {asm("nop");}
	 
void delay_us(uint n)
{
	uint i=0;
	for(i=0;i<n;i++)
	delay_1us();
}	 
	 
void delay_1ms(void) 
{
	uint i;
	for(i=1;i<(uint)(xtal*143-2);i++)
	;
}
void delay_ms(uint n)
{
   uint i=0;
   for(i=0;i<n;i++)
   delay_1ms();
}
unsigned char get_id(void)                          //读取拨码开关
{
 unsigned char temp;
 PORTC = addr_id;
 WDR();
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 temp = PINB;
 temp = ~(temp);
 temp = temp&0x7f;
 return temp;
}

void buzzer_on(void)
{
unsigned char temp;
WDR();
out_state|=0x01;
PORTC&=0xef;
 
PORTE = (out_state<<2);
PORTD |= 0x80;
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void buzzer_off(void)
{
 unsigned char temp;
WDR();
PORTC&=0xef;
out_state&=0xfe;
PORTE = (out_state<<2);
PORTD |= 0x80;
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay1_on(void)
{
unsigned char temp;
WDR();
PORTC&=0xef;
out_state|=0x02;
 PORTE = (out_state<<2);
 PORTD |= 0x80;
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay1_off(void)
{
unsigned char temp;
WDR();
PORTC&=0xef;
out_state&=0xfd;
PORTE = (out_state<<2);
PORTD |= 0x80;
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay2_on(void)
{WDR();
PORTC&=0xef;
 asm("nop");
 asm("nop");
PORTD |= 0x80;
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
PORTE |= 0x10;
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay2_off(void)
{WDR();
PORTC&=0xef;
 asm("nop");
 asm("nop");
PORTD |= 0x80;
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
PORTE &= ~(0x10);
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay3_on(void)
{WDR();
PORTC&=0xef;
 asm("nop");
 asm("nop");
PORTD |= 0x80;
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
PORTE |= 0x20;
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay3_off(void)
{WDR();
PORTC&=0xef;
 asm("nop");
 asm("nop");
PORTD |= 0x80;
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
PORTE &= ~(0x20);
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay4_on(void)
{WDR();
PORTC&=0xef;
 asm("nop");
 asm("nop");
PORTD |= 0x80;
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
PORTE |= 0x40;
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay4_off(void)
{
WDR();
PORTC&=0xef;
 asm("nop");
 asm("nop");
PORTD |= 0x80;
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
PORTE &= ~(0x40);
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay5_on(void)
{
WDR();
PORTC&=0xef;
 asm("nop");
 asm("nop");
PORTD |= 0x80;
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
PORTE |= 0x80;
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay5_off(void)
{
unsigned char temp;
WDR();
PORTC&=0xef;
 asm("nop");
 asm("nop");
PORTD |= 0x80;
 asm("nop");
 asm("nop");
 DDRE=0;
 asm("nop");
 asm("nop");
 temp = PINE;
 asm("nop");
 asm("nop");
 DDRE=0xfc;
  asm("nop");
  asm("nop");
 PORTE=temp;
 
PORTE &= ~(0x80);
 asm("nop");
 asm("nop");
PORTD &= 0x7f;
}

void relay_out_reset(void)
{
WDR();
 PORTC&=0xef;
 PORTE = 0x00;
 asm("nop");
 asm("nop");
 PORTG = 0x00;
 asm("nop");
 asm("nop");
 PORTD |= 0x80;
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 asm("nop");
 PORTD &= 0x7f;
}

void led_off(unsigned char i)
{
unsigned char temp,tempdata;
WDR();
temp = i>>3;
PORTD&=0x7f;
asm("nop");
asm("nop");
asm("nop");
switch(temp)
{
case 0: PORTC=0x10; break;
case 1: PORTC=0x90; break;
case 2: PORTC=0x50; break;
case 3: PORTC=0xd0; break;
case 4: PORTC=0x30; break;
case 5: PORTC=0xb0; break;
default:RESET;
}
asm("nop");
asm("nop");
temp = i%8;
if(temp<6) 
{
tempdata = 1<<(temp+2);
PORTE |= tempdata;
}
else
{
tempdata = 1<< (temp-3);
PORTG |= tempdata;
}

PORTC&=0xef;

}


void led_on(unsigned char i,unsigned char d,unsigned char dd,unsigned char tt)
{
 unsigned temp1,temp2,pas_flag;
 temp1= 0xfc;
 temp2= 0x18;
 PORTD&=0x7f;
 WDR();
 if(!tt)
 {
  WDR();
 pas_flag=1;
 if(d&0x01)

⌨️ 快捷键说明

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