e có điều khiển led đơn bằng ngôn ngữ C trên Keil C , nhưng chỉ đc vài chục trạng thái, sau đó e viết thêm đến khi xuất file Hex ko đc nữa, các pro chỉ e cách tối ưu hóa chương trình với, e muôn điểu khiển 4 Port của 89c51 với nhiều trạng thái.
Code:
#include<reg52.h> sbit A=P3^7; void delay(long t) { long i; for(i=0; i<=t;i++); } void main() { A=1; abc: P0=P1=P3=P2=0X00; delay(1000); P0=P1=P3=P2=0XFF; delay(3000); P0=P1=P2=P3=0X00; delay(3000); P0=P1=P3=P2=0XFF; delay(3000); P0=P1=P2=P3=0X00; delay(3000); P0=P1=P3=P2=0XFF; delay(3000); P0=P1=P2=P3=0X00; delay(3000); P0=P1=P3=P2=0XFF; delay(3000); P0=P1=P2=P3=0X00; delay(3000); P0=P1=P3=P2=0XFF; delay(3000); P0=P1=P2=P3=0X00; delay(3000); P0=P1=P3=P2=0XFF; delay(3000); P0=P1=P2=P3=0X00; delay(3000); P1=0X01; delay(3000); P1=0X02; delay(3000); P1=0X04; delay(3000); P1=0X08; delay(3000); P1=0X10; delay(3000); P1=0X20; delay(3000); P1=0X40; delay(3000); P1=0X80; delay(3000); P1=0X00; P3=0X01; delay(3000); P3=0X02; delay(3000); P3=0X04; delay(3000); P3=0X08; delay(3000); P3=0X10; delay(3000); P3=0X20; delay(3000); P3=0X40; delay(3000); P3=0X80; delay(3000); P3=0X00; P2=0X01; delay(3000); P2=0X02; delay(3000); P2=0X04; delay(3000); P2=0X08; delay(3000); P2=0X10; delay(3000); P2=0X20; delay(3000); P2=0X40; delay(3000); P2=0X80; delay(3000); P2=0X00; P0=0X80; delay(3000); P0=0X40; delay(3000); P0=0X20; delay(3000); P0=0X10; delay(3000); P0=0X08; delay(3000); P0=0X04; delay(3000); P0=0X02; delay(3000); P0=0X01; delay(3000); P0=0X00; P1=0X01; delay(2000); P1=0X02; delay(2000); P1=0X04; delay(2000); P1=0X08; delay(2000); P1=0X10; delay(2000); P1=0X20; delay(2000); P1=0X40; delay(2000); P1=0X80; delay(2000); P1=0X00; P3=0X01; delay(2000); P3=0X02; delay(2000); P3=0X04; delay(2000); P3=0X08; delay(2000); P3=0X10; delay(2000); P3=0X20; delay(2000); P3=0X40; delay(2000); P3=0X80; delay(2000); P3=0X00; P2=0X01; delay(2000); P2=0X02; delay(2000); P2=0X04; delay(2000); P2=0X08; delay(2000); P2=0X10; delay(2000); P2=0X20; delay(2000); P2=0X40; delay(2000); P2=0X80; delay(2000); P2=0X00; P0=0X80; delay(2000); P0=0X40; delay(2000); P0=0X20; delay(2000); P0=0X10; delay(2000); P0=0X08; delay(2000); P0=0X04; delay(2000); P0=0X02; delay(2000); P0=0X01; delay(2000); P0=0X00; P1=P0=0X01; delay(3000); P1=P0=0X02; delay(3000); P1=P0=0X04; delay(3000); P1=P0=0X08; delay(3000); P1=P0=0X10; delay(3000); P1=P0=0X20; delay(3000); P1=P0=0X40; delay(3000); P1=P0=0X80; delay(3000); P1=P0=0X00; P3=0X01; P2=0X80; delay(3000); P3=0X02; P2=0X40; delay(3000); P3=0X04; P2=0X20; delay(3000); P3=0X08; P2=0X10; delay(3000); P3=0X10; P2=0X08; delay(3000); P3=0X20; P2=0X04; delay(3000); P3=0X40; P2=0X02; delay(3000); P3=0X80; P2=0X01; delay(3000); P0=P1=P2=P3=0X00; P2=0X01; P3=0X80; delay(3000); P2=0X02; P3=0X40; delay(3000); P2=0X04; P3=0X20; delay(3000); P2=0X08; P3=0X10; delay(3000); P2=0X10; P3=0X08; delay(3000); P2=0X20; P3=0X04; delay(3000); P2=0X40; P3=0X02; delay(3000); P2=0X80; P3=0X01; delay(3000); P0=P1=P2=P3=0X00; P1=P0=0X80; delay(3000); P1=P0=0X40; delay(3000); P1=P0=0X20; delay(3000); P1=P0=0X10; delay(3000); P1=P0=0X08; delay(3000); P1=P0=0X04; delay(3000); P1=P0=0X02; delay(3000); P1=P0=0X01; delay(3000); P1=P0=0X01; delay(3000); P1=P0=0X02; delay(3000); P1=P0=0X04; delay(3000); P1=P0=0X08; delay(3000); P1=P0=0X10; delay(3000); P1=P0=0X20; delay(3000); P1=P0=0X40; delay(3000); P1=P0=0X80; delay(3000); P1=P0=0X00; P3=0X01; P2=0X80; delay(3000); P3=0X02; P2=0X40; delay(3000); P3=0X04; P2=0X20; delay(3000); P3=0X08; P2=0X10; delay(3000); P3=0X10; P2=0X08; delay(3000); P3=0X20; P2=0X04; delay(3000); P3=0X40; P2=0X02; delay(3000); P3=0X80; P2=0X01; delay(3000); P0=P1=P2=P3=0X00; P2=0X01; P3=0X80; delay(3000); P2=0X02; P3=0X40; delay(3000); P2=0X04; P3=0X20; delay(3000); P2=0X08; P3=0X10; delay(3000); P2=0X10; P3=0X08; delay(3000); P2=0X20; P3=0X04; delay(3000); P2=0X40; P3=0X02; delay(3000); P2=0X80; P3=0X01; delay(3000); P0=P1=P2=P3=0X00; P1=P0=0X80; delay(3000); P1=P0=0X40; delay(3000); P1=P0=0X20; delay(3000); P1=P0=0X10; delay(3000); P1=P0=0X08; delay(3000); P1=P0=0X04; delay(3000); P1=P0=0X02; delay(3000); P1=P0=0X01; delay(3000); P0=P1=P2=P3=0X00; P1=P0=0X01; delay(3000); P1=P0=0X03; delay(3000); P1=P0=0X07; delay(3000); P1=P0=0X0F; delay(3000); P1=P0=0X1F; delay(3000); P1=P0=0X3F; delay(3000); P1=P0=0X7F; delay(3000); P1=P0=0XFF; delay(3000); P0=P1=P2=P3=0X00; P3=0X01; P2=0X80; P1=P0=0XFF; delay(3000); P3=0X03; P2=0XC0; P1=P0=0XFF; delay(3000); P3=0X07; P2=0XE0; P1=P0=0XFF; delay(3000); P3=0X0F; P2=0XF0; P1=P0=0XFF; delay(3000); P3=0X1F; P2=0XF8; P1=P0=0XFF; delay(3000); P3=0X3F; P2=0XFC; P1=P0=0XFF; delay(3000); P3=0X7F; P2=0XFE; P1=P0=0XFF; delay(3000); P3=0XFF; P2=0XFF; P1=P0=0XFF; delay(3000); P0=P1=P2=P3=0X00; P2=0X01; P3=0X80; delay(3000); P2=0X03; P3=0XC0; delay(3000); P2=0X07; P3=0XE0; delay(3000); P2=0X0F; P3=0XF0; delay(3000); P2=0X1F; P3=0XF8; delay(3000); P2=0X3F; P3=0XFC; delay(3000); P2=0X7F; P3=0XFE; delay(3000); P2=0XFF; P3=0XFF; delay(3000); P2=P3=0XFF; P1=P0=0X80; delay(3000); P2=P3=0XFF; P1=P0=0XC0; delay(3000); P2=P3=0XFF; P1=P0=0XE0; delay(3000); P2=P3=0XFF; P1=P0=0XF0; delay(3000); P2=P3=0XFF; P1=P0=0XF8; delay(3000); P2=P3=0XFF; P1=P0=0XFC; delay(3000); P2=P3=0XFF; P1=P0=0XFE; delay(3000); P2=P3=0XFF; P1=P0=0XFF; delay(3000); P1=P2=P0=0X80; P3=0x01; delay(3000); P1=P2=P0=0XC0; P3=0x03; delay(3000); P1=P2=P0=0XE0; P3=0x07; delay(3000); P1=P2=P0=0XF0; P3=0x0F; delay(3000); P1=P2=P0=0XF8; P3=0x1F; delay(3000); P1=P2=P0=0XFC; P3=0x3F; delay(3000); P1=P2=P0=0XFE; P3=0x7F; delay(3000); P1=P2=P0=0XFF; P3=0xFF; delay(3000); goto abc; }
Comment