mọi người xem rùi cho ý kiến ha mình post video va code len luon tại sao nó chạy mà cứ bị giật giật chạy không đều làm sao cho nó hết giật hả các huynh
DSCN0292 - YouTube
#include <REGX51.H>
#include "font.h"
#define scan_led P2
/////////////////////////////
//////THIET LAP BAN DAU//////
#define so_led 2 //boi cu?a 8
#define so_hang 16 //chieu cao cua font chu
#define multi so_hang+1 //
#define cot_font 11 //chieu ngang cua font chu
#define en_run 1 //1: chay <----> 0 dung
////////////////////////////
typedef unsigned char uchar;
typedef unsigned int uint;
sbit rck=P3^2;
sbit srck=P3^0;
sbit ser_in=P3^1;
sbit en_hc154=P3^3;
int run=0,en=en_run;
idata uchar display_buffer[so_hang][so_led];
idata uchar shift_buffer[so_hang];
uchar row_buffer[16]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar row_led[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
uchar tocdoh=0xf6,tocdol=0xd3;
uchar kitu_code=0;
char row=multi;
void shift_dataled();
//void test_led();
void clear_buffer();
void run_string();
void copy_datacode();
void scan_dataled_code();
void init_interrupt();
////////////////////////////////
///////ngat timer 0////////////
void isr_timer0() interrupt 1 using 1
{
//clear_buffer();
TH0=tocdoh,TL0=tocdol;
if(--row==-1) row=multi-1;
shift_dataled();
if(row==so_hang)run=1;
}
////////////////////////////////
/////////chuong trinh chinh/////
void main()
{
uchar w;
init_interrupt();
//test_led();
clear_buffer();
if(en==0) scan_dataled_code();
while(1)
{
if((run==1)&(en==1)){
IE&=0xfd;
run_string(),run=0;
if(++w==8) copy_datacode(),w=0;
row=so_hang;
IE|=0x02;
}
}
}
////////////////////////////////
////////kiem tra led////////////
/*void test_led()
{
uchar i,j;
uint t_delay=100;
for(i=0;i<so_hang;i++)
for(j=0;j<so_led;j++)
display_buffer[i][j]=0xff;
while(--t_delay);
} */
void clear_buffer()
{
char i,j;
for(i=0;i<so_led;i++)
for(j=0;j<8;j++){
ser_in=0;
srck=1;
srck=0;
}
en_hc154=1;
rck=1;
rck=0;
scan_led=row_led[row];
en_hc154=0;
}
////////////////////////////////
///////dich data va quet led////
void shift_dataled()
{
char i,j;
srck=0;
rck=0;
if(row<so_hang){
for(i=0;i<so_led;i++)
for(j=0;j<8;j++){
ser_in=display_buffer[row][i]&row_buffer[7-j];
srck=1;
srck=0;
}
en_hc154=1;
rck=1;
rck=0;
scan_led=row_led[row];
en_hc154=0;
}
}
void copy_datacode()
{
uchar i;
static uchar j;
for(i=0;i<so_hang;i++)
shift_buffer[i]=Bmp002[Bmp002[2]*i+3+j];
if(++j==Bmp002[2]) j=0;
}
////////////////////////////////
////////chay chuoi//////////////
void run_string()
{
uchar i,j;
for(i=0;i<so_hang;i++)
{
for(j=0;j<so_led;j++)
{
display_buffer[i][j]<<=1;
if(j!=(so_led-1)) display_buffer[i][j]|display_buffer[i][j+1]&0x80)>>7);
else display_buffer[i][j]|shift_buffer[i]&0x80)>>7);
}
shift_buffer[i]<<=1;
}
}
void scan_dataled_code()
{
uchar i,j;
for(i=0;i<so_hang;i++){
for(j=0;j<so_led;j++){
display_buffer[i][j]=Bmp002[Bmp002[2]*i + 3+j];
}
}
}
////////////////////////////////
//////khoi dong ngat////////////
void init_interrupt()
{
TMOD=0x01; //timer0 che do 1 16b
TH0=0xF8;
TL0=0x30;
TR0=1;
TR1=1;
IE=0x82; //cho phep ngat timer0
}
DSCN0292 - YouTube
#include <REGX51.H>
#include "font.h"
#define scan_led P2
/////////////////////////////
//////THIET LAP BAN DAU//////
#define so_led 2 //boi cu?a 8
#define so_hang 16 //chieu cao cua font chu
#define multi so_hang+1 //
#define cot_font 11 //chieu ngang cua font chu
#define en_run 1 //1: chay <----> 0 dung
////////////////////////////
typedef unsigned char uchar;
typedef unsigned int uint;
sbit rck=P3^2;
sbit srck=P3^0;
sbit ser_in=P3^1;
sbit en_hc154=P3^3;
int run=0,en=en_run;
idata uchar display_buffer[so_hang][so_led];
idata uchar shift_buffer[so_hang];
uchar row_buffer[16]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar row_led[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
uchar tocdoh=0xf6,tocdol=0xd3;
uchar kitu_code=0;
char row=multi;
void shift_dataled();
//void test_led();
void clear_buffer();
void run_string();
void copy_datacode();
void scan_dataled_code();
void init_interrupt();
////////////////////////////////
///////ngat timer 0////////////
void isr_timer0() interrupt 1 using 1
{
//clear_buffer();
TH0=tocdoh,TL0=tocdol;
if(--row==-1) row=multi-1;
shift_dataled();
if(row==so_hang)run=1;
}
////////////////////////////////
/////////chuong trinh chinh/////
void main()
{
uchar w;
init_interrupt();
//test_led();
clear_buffer();
if(en==0) scan_dataled_code();
while(1)
{
if((run==1)&(en==1)){
IE&=0xfd;
run_string(),run=0;
if(++w==8) copy_datacode(),w=0;
row=so_hang;
IE|=0x02;
}
}
}
////////////////////////////////
////////kiem tra led////////////
/*void test_led()
{
uchar i,j;
uint t_delay=100;
for(i=0;i<so_hang;i++)
for(j=0;j<so_led;j++)
display_buffer[i][j]=0xff;
while(--t_delay);
} */
void clear_buffer()
{
char i,j;
for(i=0;i<so_led;i++)
for(j=0;j<8;j++){
ser_in=0;
srck=1;
srck=0;
}
en_hc154=1;
rck=1;
rck=0;
scan_led=row_led[row];
en_hc154=0;
}
////////////////////////////////
///////dich data va quet led////
void shift_dataled()
{
char i,j;
srck=0;
rck=0;
if(row<so_hang){
for(i=0;i<so_led;i++)
for(j=0;j<8;j++){
ser_in=display_buffer[row][i]&row_buffer[7-j];
srck=1;
srck=0;
}
en_hc154=1;
rck=1;
rck=0;
scan_led=row_led[row];
en_hc154=0;
}
}
void copy_datacode()
{
uchar i;
static uchar j;
for(i=0;i<so_hang;i++)
shift_buffer[i]=Bmp002[Bmp002[2]*i+3+j];
if(++j==Bmp002[2]) j=0;
}
////////////////////////////////
////////chay chuoi//////////////
void run_string()
{
uchar i,j;
for(i=0;i<so_hang;i++)
{
for(j=0;j<so_led;j++)
{
display_buffer[i][j]<<=1;
if(j!=(so_led-1)) display_buffer[i][j]|display_buffer[i][j+1]&0x80)>>7);
else display_buffer[i][j]|shift_buffer[i]&0x80)>>7);
}
shift_buffer[i]<<=1;
}
}
void scan_dataled_code()
{
uchar i,j;
for(i=0;i<so_hang;i++){
for(j=0;j<so_led;j++){
display_buffer[i][j]=Bmp002[Bmp002[2]*i + 3+j];
}
}
}
////////////////////////////////
//////khoi dong ngat////////////
void init_interrupt()
{
TMOD=0x01; //timer0 che do 1 16b
TH0=0xF8;
TL0=0x30;
TR0=1;
TR1=1;
IE=0x82; //cho phep ngat timer0
}
Comment