//GPIO.H
#ifndef _GPIO_H_
#define _GPIO_H_
enum pn{
p0 = 0, p1 = 1,
p2 = 2, p3 = 3,
};
void gao(unsigned char pn,
unsigned char pin);
void di(unsigned char pn,
unsigned char pin);
#endif
//gpio.c
#include <reg52.h>
#include <GPIO.h>
void gao(unsigned char pn,
unsigned char pin)
{
unsigned char i = 1;
i = i<<pin;
switch(pn){
case 0:
P0 |= i;
break;
case 1:
P1 |= i;
break;
case 2:
P2 |= i;
break;
case 3:
P3 |= i;
break;
}
}
void di(unsigned char pn,
unsigned char pin)
{
unsigned char i=1;
i = i<<pin;
switch(pn){
case 0:
P0 &= ~i;
break;
case 1:
P1 &= ~i;
break;
case 2:
P2 &= ~i;
break;
case 3:
P3 &= ~i;
break;
}
}
//main.c
#include <reg52.h>
#include <GPIO.h>
void delay(int n){
int i,j;
for(i=0;i<n;i++)
for(j=0;j<1000;j++);
}
void main(){
int j;
while(1){
for(j=0;j<8;j++){
gao(p2,j);
delay(100);
di(p2,j);
delay(100);
}
}
}