⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 max7219驱动c51源程序.txt

📁 这是一段MAX7219的驱动C51源程序
💻 TXT
字号:
max7219驱动C51源程序 
 

 文章编号:3----加入日期:2004-8-26
 
sbit DIN=P2^5;
sbit CLK=P2^4;
sbit LOAD=P2^3;    //根据实际情况定义
void send(uchar add,uchar dat)//发送16字节子函数
{ uchar ADS,i,j;
   LOAD=0;
   i=0;
   while(i<16)
   {
       if(i<8)
       {  ADS = add;}
       else {ADS=dat;}
       for(j=8;j>=1;j--)
       {
            DIN=ADS&0x80;
            ADS=ADS<<1;
            CLK=1;
            _nop_();
            _nop_();
            _nop_();
            _nop_();
            CLK=0;
       }
       i=i+8;
   }
   LOAD=1;
}

send(0x0c,0x01); //初始化MAX7219
send(0x0b,0x07); //扫描位限制控制器
send(0x0a,0xf5); //亮度寄存器
send(0x09,0xff); //译码控制寄存器

 






MAX7219测试程序 
 
作者:佚名    文章来源:中国EDA技术网    点击数:685    更新时间:2004-10-2 
说明:MAX7219是美国MAXIM公司推出的三线串行8位LED显示驱动器,具有多种显示(可控)方式。

;Program Test MAX7219
;This program is used to test whether MAX7219 is Ok and give a demo about ho
w to use it.
;Program Writed by Ouyijie, 1998.10
;Jialijie Computer Studio
PCL EQU 2 ;PCL = 2
DCOMMAND EQU 0x0d
DDATA EQU 0x0e
MCU_Reset
;I/O RB1 is Clock line
;I/O RB2 is LOAD line
;I/O RB3 is DATA line
;I/O RB4 is LED ,show state
movlw b'00000000' ;set first I/O direction
tris 6
movlw b'00000000' ;set first I/O state
movwf 0x06
Start
call MAX7219_Reset
comf 0x06,f
call Delay1s
goto Start
MAX7219_Reset ;reset MAX7219
;0x0d is display command
;0x0e is display data
movlw 0x0c
movwf DCOMMAND
movlw 0x00
movwf DDATA
call Write7219 ;write in 0c00H, shut down MAX7219.
call Delay1ms ;wait leaest 250us.
movlw 0x09
movwf DCOMMAND
movlw 0x3f
movwf DDATA
call Wr ite7219 ;write in 091fH, digits 0 to 5 are transcode.
call Delay1ms
movlw 0x0a
movwf DCOMMAND
movlw 0x0a
movwf DDATA
call Write7219 ;write in 0a0fH, set MAX7219 is the brightest state.
call Delay1ms
movlw 0x0b
movwf DCOMMAND
movlw 0x05
movwf DDATA
call Write7219 ;set SCAN LIMIT is digits 0 to 5.
call Delay1ms
;movlw 0x0f
;movwf DCOMMAND
;movlw 0x00
;movwf DDATA
;call Write7219 ;wirte in 0f00H, exit TEST, go into normal state.
;call Delay1ms
;Begin set Digit Datas
movlw 0x01
movwf DCOMMAND
movlw 0x00
movwf DDATA
call Write7219 ;bit0 is 0
call Delay1ms
movlw 0x02
movwf DCOMMAND
movlw 0x01
movwf DDATA
call Write7219 ;bit1 is 1
call Delay1ms
movlw 0x03
movwf DCOMMAND
movlw 0x02 ;bit2 is 2
movwf DDATA
call Write7219
call Delay1ms
movlw 0x04
movwf DCOMMAND
movlw 0x03 ;bit3 is 3
movwf DDATA
call Write7219
call Delay1ms
movlw 0x05
movwf DCOMMAND
movlw 0x04 ;bit4 is 4
movwf DDATA
call Write7219
call Delay1ms
movlw 0x06
movwf DCOMMAND
movlw 0x05
movwf DDATA
call Write7219 ;bit5 is 5
call Delay1ms
;Begin Display
movlw 0x0c
movwf DCOMMAND
movlw 0x01
movwf DDATA
call Write7219 ;write in 0c01H, exit shut down state.
call Delay1s ;wait for 3 seconds.
;call Delay1s
;call Delay1s
;movlw 0x0c
;movwf DCOMMAND
;movlw 0x00
;movwf DDATA
;call Write7219 ;write in 0c00H, shut down MAX7219.
call Delay1s
return
AddressTable ;list of display data
addwf PCL
retlw 0x0 ;NO-OP
retlw 0x1 ;DIG 0
retlw 0x2 ;DIG 1
retlw 0x3 ;DIG 2
retlw 0x4 ;DIG 3
retlw 0x5 ;DIG 4
retlw 0x6 ;DIG 5
retlw 0x7 ;DIG 6
retlw 0x8 ;DIG 7
retlw 0x9 ;DECODE MODE
retlw 0xa ;INTENSITY
retlw 0xb ;SCAN LIMIT
retlw 0xC ;SHUIDOWN
Write7219
;this function use address 0x0c,0x0d,0x0e,0x0f.
;address 0x0c is data send to MAX7219
;address 0x0d is display command
;address 0x0e is display data
;address 0x0f is cont used
;write address 0x0c to MAX7219 each time
bcf 0x06,2 ;set LOAD is low and MAX7219 begin to recive data
movlw 0x08
movwf 0x0f
movf DCOMMAND,w ;send display address to MAX7219
movwf 0x0c
call SendData
movlw 0x08
movwf 0x0f
movf DDATA,w ;send display data to MAX7219
movwf 0x0c
call SendData
;set a puls from LOAD to MAX7219
bcf 0x06,2 ;LOAD = 0
bsf 0x06,2 ;LOAD = 1
nop ;wait 3 comand times.
nop
nop
bcf 0x06,2 ;LOAD = 0
nop
return
SendData
;this function is used to send data in address 0x0c to MAX7219 from the high
est place.
bcf 0x06,3 ;CLOCK = 0
bcf 0x06,1 ;DATA = 0
btfsc 0x0c,7 ;if bit7 of 0x0c is 0 then skip next command.
bsf 0x06,1 ;DATA = 1
nop
nop
nop ;wait 3 command times.
nop
nop
bsf 0x06,3 ;CLOCK = 1
nop
nop
nop ;delay 5 comand times and clean the Watchdog.
clrwdt
nop
nop
nop
nop
nop
bcf 0x06,3 ;CLOCK = 0
rlf 0x0c,1 ;0x0c move left a bit.
decfsz 0x0f,1 ;0x0f = 0x0f - 1, if x00f = 0 then return to Write7219.
goto SendData
return
Delay1ms
movlw 0x28 ;0x25 = 40D = 28H
movwf 0x0c
delay1ms_loop1
movlw 0x05
movwf 0x0f
delay1ms_loop2 ;40 * 25 = 1000 us = 1ms
clrwdt ;clean watchdog
decfsz 0x0f,1
goto delay1ms_loop2
decfsz 0x0c,1
goto delay1ms_loop1
return
Delay1s
movlw 0xce ;every time use 4.85ms, 1000/4.85=206.1D=CEH
movwf 0x1a
delay1s_loop1
movlw 0x05
movwf 0x1b
delay1s_loop2 ;4.85 ms * 206 = 1 s
clrwdt
call Delay1ms
decfsz 0x1b,1
goto delay1s_loop2
decfsz 0x1a,1
goto delay1s_loop1
return
end 
 




·max7219 C语言驱动程序     -|wolf0801 发表于 2005-8-25 9:16:00  
 

//max7219 led drive program
//for 51 mcu
//designed by zhaoliang
//2005-6-12 13:52
#i nclude<reg51.h> 

/***********************************************************************/
//common part 
#define  HIGH     1
#define  LOW      0
#define  TRUE      1
#define  FALSE      0
#define  ZERO      0 
#define  MSB       0x80
#define  LSB       0x01
//max7219 part
#define  DECODE_MODE   0x09 
#define  INTENSITY     0x0A 
#define  SCAN_LIMIT    0x0B 
#define  SHUT_DOWN     0x0C 
#define  DISPLAY_TEST  0x0F 

//pin defined
/***********************************************************************/
//change this part at different board
sbit LOAD=P1^2; //MAX7219    Load-Data Input:    rising edge  pin 12 
sbit DIN=P1^1; //MAX7219    Serial-Data Input:   rising edge  pin 1
sbit CLK=P1^0; //MAX7219   Serial-Clock Input:  maximum 10MHz  pin 13

//function define
/***********************************************************************/
void Write_Max7219_byte(unsigned char temp);//write max7219 a byte
void Write_Max7219(unsigned char address,unsigned char dat);//write max7219 command and data
void Init_Max7219(void);//Initize max7219

//test program display from 1~8
/***********************************************************************/
void main(void)
{
 unsigned char i; 
 Init_Max7219();  
 while(TRUE)
 {  
  for(i=1;i<9;i++) 
  {
   Write_Max7219(i,i);
  }
 } 
}
/***********************************************************************/
void Write_Max7219_byte(unsigned char temp)
{
 unsigned char i;
 for (i=0;i<8;i++)     
  { 
   CLK=LOW;
     DIN=(bit)(temp&MSB);      
     temp<<=1;  
     CLK=HIGH;
   }
}
/***********************************************************************/
void Write_Max7219(unsigned char address,unsigned char dat)
{ 
 LOAD=LOW;
   Write_Max7219_byte(address); 
   Write_Max7219_byte(dat);
  LOAD=HIGH;                 
}
/***********************************************************************/
void Init_Max7219(void)      
{ 
 Write_Max7219(SHUT_DOWN, 0x01);   //Normal Operation XXXXXXX1 Shutdown Mode   XXXXXXXX0
 Write_Max7219(DISPLAY_TEST, 0x00);   //Normal Operation XXXXXXX0 Display Test Mode XXXXXXXX1
 Write_Max7219(DECODE_MODE, 0xff);   //Decode Mode Select D7~D0 1 B decode 0 No decode 
 Write_Max7219(SCAN_LIMIT, 0x07);   //SCAN LIMIT 0~7 0xX0~0xX7
 Write_Max7219(INTENSITY, 0x04);   //Set Intensity   0xX0~0xXf

 

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -