学习C51单片机——LED点阵屏显示爱心(学习笔记Keil5)

时间:2025-03-07 16:38:05
#include <> sbit RCL = P3^5; //定义RCLK串口 sbit SCK = P3^6; //定义SRCLK串口 sbit SER = P3^4; //定义SER串口 void Delay(unsigned int xms)//延时函数 { unsigned char i, j; while(xms--) { i = 2; j = 239; do { while (--j); } while (--i); } } void SendByte(unsigned char data1)//行显示 { unsigned char a; SCK = 1; RCL = 1; for(a=0;a<8;a++) //发送8位数 { SER = data1 >> 7; //从最高位开始发送 data1 <<= 1; SCK = 0; //发送时序 SCK = 1; } RCL = 0; RCL = 1; } void main() { while(1) { P0 = 0xBF;//1011 1111 SendByte(0x30);//0011 0000 Delay(1); SendByte(0x00);//0000 0000 P0 = 0xFF; Delay(1); P0 = 0xDF;//1101 1111 SendByte(0x48);//0100 1000 Delay(1); SendByte(0x00);//0000 0000 P0 = 0xFF; P0 = 0xEF;//1110 1111 SendByte(0x24);//0010 0100 Delay(1); SendByte(0x00);//0000 0000 P0 = 0xFF; P0 = 0xF7;//1111 0111 SendByte(0x24);//0010 0100 Delay(1); SendByte(0x00);//0000 0000 P0 = 0xFF; P0 = 0xFB;//1111 1011 SendByte(0x48);//0100 1000 Delay(1); SendByte(0x00);//0000 0000 P0 = 0xFF; P0 = 0xFD;//1111 1101 SendByte(0x30);//0011 0000 Delay(1); SendByte(0x00);//0000 0000 P0 = 0xFF; Delay(1); } }