Kênh Tên Miền chuyên cung cấp tên miền đẹp, giá rẻ! Hãy liên hệ kỹ thuật: 0914205579 - Kinh doanh: 0912191357 để được tư vấn, hướng dẫn miễn phí, Cảm ơn quý khách đã ủng hộ trong thời gian qua!
Tuesday, September 10, 2013




Lập trình điều khiển bằng IC 89C51 + IC 74HC595 + 74HC154

- CHƯƠNG TRÌNH CODE ASM: COMPILE BY PINNALE

;********************************************************************************
;**************//////------------ MATRIX 16x64 ----------\\\\\\******************
;**------------------------------------------------------------------------------
;**////////////////__ Chuong trinh chay chu tren bo led ___\\\\\\\\\\\\\\\\\\\\\\
;**///////////////__ ma tran 8x8 loai 1 mau ________________\\\\\\\\\\\\\\\\\\\\\
;**//////////////___ Su dung vi dieu khien 89C52 cua ATMEL __\\\\\\\\\\\\\\\\\\\\
;**<<<<<<<<<<<<<---------------------------------------------->>>>>>>>>>>>>>>>>>>
;**\\\\\\\\\\\\\\ __ Thuc hien bien doi du lieu noi tiep ____////////////////////
;**\\\\\\\\\\\\\\\ ___ sang song song roi dua ra day led ___/////////////////////
;**\\\\\\\\\\\\\\\\ ---------- By Tien Huy  ---------- //////////////////////
;********************************************************************************
;*****
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@ CAC TEN BIT DUNG TRONG CHUONG TRINH @@@
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
en_hc154 bit p3.3
sh_cp BIT P3.0
data_serial BIT P3.1
st_cp BIT P3.2
f_run BIT 7FH ;cho phep chay

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@ CAC TEN BYTE DUNG TRONG CHUONG TRINH @@@
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
data_row equ p2 ;dia chi hang
index_byte_row equ 30h

num_row equ 16
num_byte_collum equ 8

index_point equ 31h
index_reg1 equ 32h
index_reg2 equ 33h
num_bit equ 34h
width_byte equ 35h
buffer_dptrh equ 36h
buffer_dptrl equ 37h
buffer_dptrh1 equ 38h
buffer_dptrl1 equ 39h
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@ start@@@
;@@@ OSC 12Mhz@@@
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

org 0000h
ljmp main
org 000bh
ljmp ngat_timer0
org 0030h
main:
clr f_run ;dung 
mov num_bit,#0 ;
mov dptr,#string_code+2 ;dia chi width_byte
mov a,#0
movc a,@a+dptr
mov width_byte,a ;luu tru width_byte vao ram
mov dptr,#string_code-5 
lcall set_index_dptr
mov buffer_dptrh1,dph
mov buffer_dptrl1,dpl
mov dptr,#string_code+3;DPTR =010B
mov buffer_dptrh,dph 
mov buffer_dptrl,dpl
mov index_point,#0
mov index_byte_row,#0
lcall init_interrupt
ljmp begin
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;#######################################################################################
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
begin:
___here:
mov ie,#82h
jnb f_run,___here
mov ie,#0
clr f_run
inc num_bit
mov a,num_bit
cjne a,#9,___here
;mov ie,#0
mov num_bit,#0
mov a,dpl
cjne a,buffer_dptrl1,___skip3
mov a,dph
cjne a,buffer_dptrh1,___skip3
mov dptr,#string_code+3
mov buffer_dptrh,dph
mov buffer_dptrl,dpl
mov index_byte_row,#0
sjmp ___here
___skip3:
inc dptr
mov buffer_dptrh,dph
mov buffer_dptrl,dpl
;mov ie,#82h
sjmp ___here
sjmp $
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;#######################################################################################
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
init_interrupt:
mov tmod,#01h
setb tr0
setb tf0 ;ep ngat timer0
mov ie,#82h ;cho phep ngat timer0
ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;#######################################################################################
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ngat_timer0:
mov th0,#0f3h
mov tl0,#0a8h ;12^6/12/50hz/16=1250(fb1e) 
lcall shift_data
lcall set_index_dptr
inc index_byte_row
mov a,index_byte_row
cjne a,#num_row,___exit
mov index_byte_row,#0
mov dph,buffer_dptrh
mov dpl,buffer_dptrl
setb f_run
___exit:
reti
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;#######################################################################################
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shift_data:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov index_reg1,#num_byte_collum ;num_byte_collum=8
___loop1:
mov index_reg2,#8 
mov a,index_point ;index_point start=0
movc a,@a+dptr ;LAY DU LIEU TRONG BO NHO CT ;DPTR start=010Bh
___loop2:
clr c
rlc a
mov data_serial,c
clr sh_cp
setb sh_cp
djnz index_reg2,___loop2 ;dich du 8 bit
inc index_point ;tang index_point de tro den dia chi tiep theo
djnz index_reg1,___loop1 ;dich du 8 byte
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov a,num_bit ;de kiem tra co zero ;num_bit start=0
jz ___skip1
mov index_reg2,num_bit
mov a,index_point
movc a,@a+dptr ;LAY DU LIEU TRONG BO NHO CT
___loop3:
clr c
rlc a
mov data_serial,c
clr sh_cp
setb sh_cp
djnz index_reg2,___loop3 ;dich du 8 bit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
___skip1:
setb en_hc154 ;ta't ma`ng hi`nh de^? cho^'ng lem led
clr st_cp ;thuc hien chot du lieu
setb st_cp
mov data_row,index_byte_row ;chon hang va tich cuc hc154 ;index_byte_row start=0
clr en_hc154 ;bat lai man hinh
mov index_point,#0 ;gia tri ban dau
ret

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;#######################################################################################
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set_index_dptr:
mov a,dpl
add a,width_byte
mov dpl,a ;DPTR start=122h
jnc ___skip2 ;neu khong co nho
inc dph 
___skip2:
ret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;#######################################################################################
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
string_code:

;unsigned char code Bmp002:
;-------------------------------------------------------------------------------
; If font display distortion, please check Fonts format of setup.
; Source file / text :           Líp ®iÖn tö K2           
; Width x Height (pixels) :243X16
;  Font Format/Size : Monochrome LCD Fonts ,Horizontal scan ,Big endian order/496Byte
;  Font make date  : 10/11/2009 7:37:17 AM
;-------------------------------------------------------------------------------
DB 0F3H,010H,01FH;Width pixels,Height pixels,Width bytes
DB 000H,000H,000H,000H,000H,000H,000H,000H,001H,080H,000H,000H,001H,000H,000H,000H
DB 000H,000H,007H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,001H,0FEH,001H,080H,000H,000H,01FH,03CH,038H,000H,000H
DB 000H,001H,000H,03FH,09FH,01FH,080H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,0F8H,003H,000H,000H,000H,07FH,0BCH,028H,000H,000H,002H
DB 002H,018H,01FH,008H,063H,0C0H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,0F8H,004H,038H,000H,000H,00FH,03CH,064H,000H,000H,006H,004H
DB 038H,01FH,010H,07BH,0E0H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,0F8H,000H,038H,000H,000H,04FH,000H,000H,000H,000H,00EH,000H,03CH
DB 01FH,030H,07BH,0E0H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,0F8H,007H,0F3H,0EEH,001H,0FFH,07CH,07CH,07DH,0C0H,03FH,0FFH,0F0H,01FH
DB 078H,003H,0E0H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,0F8H,00EH,079H,0FFH,001H,0EFH,03CH,0EEH,03FH,0E0H,01EH,03DH,0E0H,01FH,0F8H
DB 003H,0C0H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 0F8H,01EH,079H,0EFH,083H,0EFH,03DH,0EFH,03DH,0E0H,01EH,03DH,0E0H,01FH,07CH,00EH
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,0F8H
DB 05EH,079H,0EFH,083H,0EFH,03DH,0FFH,03DH,0E0H,01EH,03DH,0E0H,01FH,07EH,010H,020H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,0F8H,05EH
DB 079H,0EFH,003H,0EFH,03DH,0E0H,03DH,0E0H,01EH,0BDH,0E0H,01FH,03EH,02FH,0E0H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,0F8H,0CEH,071H
DB 0EFH,001H,0EFH,03CH,0E1H,03DH,0E0H,01EH,0BDH,0E0H,01FH,01FH,07FH,0E0H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,001H,0FFH,0C7H,0E1H,0FEH
DB 000H,0FFH,0FEH,076H,07DH,0F0H,01FH,03FH,0F0H,03FH,0BFH,0FFH,080H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,001H,0E0H,000H
DB 000H,000H,008H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,001H,0E0H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,001H,0E0H,000H,000H,000H
DB 038H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,003H,0F0H,000H,000H,000H,038H
DB 000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H


end

- CHƯƠNG TRÌNH CODE C: COMPILE BY KEIL C

      /* CHUONG TRINH HIEN led matric 16x64
  Version: 2.3 using test
  Date: 3-10-2009
  Programer: huyhtqn@gmail.com
  Checksum:
  Hien thi led matric       */

#include "regx51.h"
#include "font_code.h"
#define scan_led P2
/////////////////////////////
//////THIET LAP BAN DAU//////
#define so_led 8   //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;

bit 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=0x00;
uchar kitu_code=0;
char row=multi;//multi=17
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
{
   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=10000;
   for(i=0;i<so_hang;i++) //hang =16
      for(j=0;j<so_led;j++) //so led=8
         display_buffer[i][j]=0xff;
   while(--t_delay); 
}
void clear_buffer()
{
   uchar i,j;
   for(i=0;i<so_hang;i++)
      for(j=0;j<so_led;j++)
         display_buffer[i][j]=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]; //dich bit thu 7-j vao ic dich
            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 
}      

File Font của code C:

unsigned char code Bmp002[]=
{
/*------------------------------------------------------------------------------
; If font display distortion, please check Fonts format of setup.
; Source file / text :           Líp ®iÖn tö K2           
; Width x Height (pixels) :243X16
;  Font Format/Size : Monochrome LCD Fonts ,Horizontal scan ,Big endian order/496Byte
;  Font make date  : 10/11/2009 7:32:20 AM
------------------------------------------------------------------------------*/
0xF3,0x10,0x1F,//Width pixels,Height pixels,Width bytes
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0xFE,0x01,0x80,0x00,0x00,0x1F,0x3C,0x38,0x00,0x00,
0x00,0x01,0x00,0x3F,0x9F,0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xF8,0x03,0x00,0x00,0x00,0x7F,0xBC,0x28,0x00,0x00,0x02,
0x02,0x18,0x1F,0x08,0x63,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xF8,0x04,0x38,0x00,0x00,0x0F,0x3C,0x64,0x00,0x00,0x06,0x04,
0x38,0x1F,0x10,0x7B,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xF8,0x00,0x38,0x00,0x00,0x4F,0x00,0x00,0x00,0x00,0x0E,0x00,0x3C,
0x1F,0x30,0x7B,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xF8,0x07,0xF3,0xEE,0x01,0xFF,0x7C,0x7C,0x7D,0xC0,0x3F,0xFF,0xF0,0x1F,
0x78,0x03,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xF8,0x0E,0x79,0xFF,0x01,0xEF,0x3C,0xEE,0x3F,0xE0,0x1E,0x3D,0xE0,0x1F,0xF8,
0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xF8,0x1E,0x79,0xEF,0x83,0xEF,0x3D,0xEF,0x3D,0xE0,0x1E,0x3D,0xE0,0x1F,0x7C,0x0E,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,
0x5E,0x79,0xEF,0x83,0xEF,0x3D,0xFF,0x3D,0xE0,0x1E,0x3D,0xE0,0x1F,0x7E,0x10,0x20,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x5E,
0x79,0xEF,0x03,0xEF,0x3D,0xE0,0x3D,0xE0,0x1E,0xBD,0xE0,0x1F,0x3E,0x2F,0xE0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xCE,0x71,
0xEF,0x01,0xEF,0x3C,0xE1,0x3D,0xE0,0x1E,0xBD,0xE0,0x1F,0x1F,0x7F,0xE0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xC7,0xE1,0xFE,
0x00,0xFF,0xFE,0x76,0x7D,0xF0,0x1F,0x3F,0xF0,0x3F,0xBF,0xFF,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,
0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,
0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x38,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

( File Mô Phỏng + Code)
Khi nhấn nút "Tải Về Máy", bạn sẽ vào trang quảng cáo, vui lòng chờ 5 giây. Nút  hiện ra ở góc phải phía trên, nhấn vào để đến trang download

Echipkool - Chia sẻ kiến thức - Kết nối đam mê điện tử

0 comments:

Post a Comment

domain, domain name, premium domain name for sales

Popular Posts