STC89C51單片機點亮8x8點陣
#include <REGX51.H>
//延時n毫秒12mHz
void delay(unsigned int n)
{
unsigned int i=0,j=0;
for(i=0;i<n;i++)
for(j=0;j<123;j++);
}
//傳遞參數(shù)
void send(int num)
{
P0 = 0x7f; //y
P1 = 0xff; //x
switch(num)
{
case 0:
P0=(0x01<<0);
P1=0xe7;
break;
case 1:
P0=(0x01<<1);
P1=0xc3;
break;
case 2:
P0=(0x01<<2);
P1=0x81;
break;
case 3:
P0=(0x01<<3);
P1=0x00;
break;
case 4:
P0=(0x01<<4);
P1=0x00;
break;
case 5:
P0=(0x01<<5);
P1=0x81;
break;
case 6:
P0=(0x01<<6);
P1=0xdb;
break;
case 7:
P0=(0x01<<7);
break;
}
}
void main()
{
while(1)
{
unsigned int i;
for(i=0;i<8;i++)
{
//循環(huán)傳遞參數(shù)
send(i); // x,y
delay(1);
}
}
}