Nguyên văn bởi known
Xem bài viết
8051 CD-Rom Player
#include <REGX51.H>
char rightLeft[] = {0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
void delay(int time){ //Tao tre
while(time--);
}
//---------------------------------------------------
void blink(int moreTimes){ //Nhap nhay
int i;
for(i=0;i<moreTimes;i++){
P1 = 0;
delay(10000);
P1 = 0xff;
delay(10000);
}
}
//---------------------------------------------------
void sweep(){ //Quet
int i;
for(i=0;i<8;i++){
P1 = rightLeft[1];
delay(10000);
}
}
//---------------------------------------------------
void main(){
while(1)
//blink(5);
sweep();
}

#include"main.h"
#include"delay.h"
// Khai bao ket noi chan IC
sbit IE595_SHCP = P2^0;
sbit IE595_DS = P2^1;
sbit IE595_STCP = P2^2;
//-------------------------
void ID595_byte_out(unsigned char b){
unsigned char i;
for(i=0;i<8;i++){
IE595_DS = b & (0x80>>i); // Lay byte gui ra chan IE595_DS.
//------------- Tao xung dich du lieu ---------------------------
IE595_SHCP = 0;
IE595_SHCP = 1;
}
//------------- Tao xung xuat du lieu ---------------------------
IE595_STCP = 0;
IE595_STCP = 1;
}
void chopLed(unsigned char soLan){
unsigned char b,i,j;
b = 0;
for(j=0;j<soLan;j++){
for(i=0;i<soLan;i++){
ID595_byte_out(b);;
delay(100);
ID595_byte_out(b);
delay(300);
b = ~b;
}
}
}
void sangDanLed(unsigned char soLan){
unsigned char b,i,j;
b = 0;
for(j=0;j<8;j++){
for(i=0;i<soLan;i++){
ID595_byte_out(b);;
delay(100);
b = (b<<1)|0x01;
ID595_byte_out(b);
delay(300);
}
}
}
void main(){
while(1){
sangDanLed(3);
chopLed(3);
}
}
Comment