这个是按下按键闪灯就变
/*
* GccApplication2.c
*
* Created: 2014-9-23 21:41:01
* Author: Administrator
*/
#include <avr/io.h>
#define uchar unsigned char
#define uint unsigned int
//定义开关及LED与端口的连接
#define switch1 6//PIND.6
#define switch2 7//PIND.7
#define redLED1 0//PORTC.0
#define blueLED1 1//PORTC.1
#define greenLED1 2//PORTC.2
#define yellowLED1 3//PORTC.3
#define redLED2 4//PORTC.4
#define blueLED2 5//PORTC.5
#define greenLED2 6//PORTC.6
#define yellowLED2 7//PORTC.7
void delay(uint k)
{ uint m,n;
for(m=0;m<k;m++)
{
for(n=0;n<1140;n++)
{;}
}
}
int main(void)
{ DDRC=0xFF;
PORTC=0xFF;
DDRD=0x00;
PORTD=0xFF;
while(1)
{if (((PIND&switch1)==0) || ((PIND&switch2)==0))
{if ( (PIND&switch1)==0)
{
PORTC &=~redLED1;
PORTC |= blueLED1;
PORTC |= greenLED1;
PORTC &= ~yellowLED1;
PORTC |= redLED2;
PORTC |=blueLED2;
PORTC |=greenLED2;
PORTC |=yellowLED2;
delay(500);}
}
else
{
PORTC |=redLED1;
PORTC &=~blueLED1;
PORTC &=~greenLED1;
PORTC |=yellowLED1;
PORTC |= redLED2;
PORTC |=blueLED2;
PORTC |=greenLED2;
PORTC |=yellowLED2;
delay(500);
}
}
}
原程序:
|