Thông báo

Collapse
No announcement yet.

Help me toàn diễn đàn điện tử việt nam

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Help me toàn diễn đàn điện tử việt nam

    các pro cho E hỏi về cái lập trình Keil C cho LED matrix
    E đang làm bt lớn về Mạch LED matrix 16x84, nhưng mà đang mắc cái phần viết chương trình, hôm trước E nhờ A Ngô Hải Bắc, Nhưng A đang bận
    E sưu tầm dc 1 cái code trên mạng về.
    code:
    Code:
    	   /* 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 "regx52.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 unsigned char display_buffer[so_hang][so_led];
    idata unsigned char shift_buffer[so_hang];
    unsigned char row_buffer[16]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
    unsigned char row_led[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
    unsigned char tocdoh=0xf6,tocdol=0x00;
    unsigned char 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
    {
    	TH0=tocdoh,TL0=tocdol; 
    	if(--row==-1) row=multi-1;
    	shift_dataled();
    	if(row==so_hang) run=1;
    }
    ////////////////////////////////
    /////////chuong trinh chinh/////
    void main()
    {
    	unsigned char 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()
    {
    	unsigned char i,j;
    	unsigned int t_delay=10000;
    	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()
    {
    	unsigned char 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];
    				srck=1;
    				srck=0;
    			}
    		en_hc154=1;
    		rck=1;
    		rck=0;
    		scan_led=row_led[row];
    		en_hc154=0;
    	}
    	
    }
    void copy_datacode()
    {
    	unsigned char i;
    	static unsigned char 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()
    {
    	unsigned char 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()
    {
    	unsigned char 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 16bit
    	TH0=0xF8;
    	TL0=0x30;
    	TR0=1;
    	TR1=1;
    	IE=0x82;	//cho phep ngat timer0 
    }
    và file FONT_CODE.H
    code:
    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: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,
    };
    khai báo unsigned char code Bmp002[]={}
    thì lấy những giá trị kia bằng cách nào, theo e biết đó la mã ký tự
    rất mong dc các pro jup đỡ ạ

Về tác giả

Collapse

anhthaohn Tìm hiểu thêm về anhthaohn

Bài viết mới nhất

Collapse

Đang tải...
X