电路图
程序
1 /*============================== 2 点亮点阵心形 3 ================================*/ 4 #include <REGX51.H> 5 #include <intrins.h> 6 7 #define uchar unsigned char 8 #define uint unsigned int 9 10 sbit st_cpA = P1^4; 11 sbit sh_cpA = P1^7; 12 sbit dsA = P1^6; 13 14 sbit st_cpB = P1^2; 15 sbit sh_cpB = P1^0; 16 sbit dsB = P1^1; 17 18 void sendMessageA(uchar messageA);//发送一个字节到移位寄存器中 列 19 void outputMessageA();//输出到存储寄存器中 20 void sendMessageB(uchar messageB); //行 21 void outputMessageB(); 22 void delay(uchar time_delay); 23 24 uchar code rows[] = { 0x01, 0x02, 0x04, 0x08, 25 0x10, 0x20, 0x40, 0x80}; 26 uchar code cols[] = { 0xc9, 0xb6, 0xbe, 0xdd, 27 0xeb, 0xf7, 0xff, 0xff}; 28 void main() 29 { 30 uchar i = 0; 31 while(1) 32 { 33 //扫描显示 34 for(i = 0; i < 8; i++) 35 { 36 sendMessageB(rows[i]); 37 outputMessageB(); 38 sendMessageA(cols[i]); 39 outputMessageA(); 40 //delay(5000); 41 } 42 } 43 } 44 45 void sendMessageA(uchar messageA) 46 { 47 uchar i = 0; 48 for(; i < 8; i ++) 49 { 50 sh_cpA = 0; 51 dsA = messageA & 0x80;//先写入最高位 52 messageA = messageA << 1;//左移移位 53 sh_cpA = 1; 54 } 55 } 56 void sendMessageB(uchar messageB) 57 { 58 uchar i = 0; 59 for(; i < 8; i ++) 60 { 61 sh_cpB = 0; 62 dsB = messageB & 0x80;//先写入最高位 63 messageB = messageB << 1;//左移移位 64 sh_cpB = 1; 65 } 66 } 67 void outputMessageA() 68 { 69 st_cpA = 0; 70 _nop_(); 71 st_cpA = 1; 72 } 73 void outputMessageB() 74 { 75 st_cpB = 0; 76 _nop_(); 77 st_cpB = 1; 78 } 79 //延时函数 80 void delay(uchar time_delay) 81 { 82 uchar x,y; 83 for(x = time_delay; x > 0; x --) 84 for(y = time_delay; y > 0; y--) 85 {} 86 }