max7219顯示程序(匯編)
#include "msp430x41x.h"
DIN EQU 001H ;P1.0
CLK EQU 002H ;P1.1
LOAD EQU 004H ;P1.2
ORG 0F000H
RESET MOV #300H,SP ;初始化
MOV #WDTPW+WDTHOLD,&WDTCTL
BIS.B #CLK,&P1DIR
BIS.B #DIN,&P1DIR
BIS.B #LOAD,&P1DIR
PUSH #00C01H ;設(shè)置工作模式
BIC.B #LOAD,&P1OUT
CALL #MOVE
BIS.B #LOAD,&P1OUT
PUSH #00B05H ;設(shè)置掃描位數(shù)
BIC.B #LOAD,&P1OUT
CALL #MOVE
BIS.B #LOAD,&P1OUT
PUSH #009FFH ;設(shè)置編碼方式
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00A07H ;設(shè)置亮度
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
XIAN PUSH #00107H ;顯示第一位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00206H ;顯示第二位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00305H ;顯示第三位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00404H ;顯示第四位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00503H ;顯示第五位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00602H ;顯示第六位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
JMP $
MOVE MOV.B #16,R6
MOV 2(SP),R13
MOV #1,R10
SENDLOOP BIC.B #CLK,&P1OUT
BIT R10,R13
JNZ SEND1
SEND0 BIC.B #DIN,&P1OUT
JMP GOON
SEND1 BIS.B #DIN,&P1OUT
GOON BIS.B #CLK,&P1OUT
RLA R10
BIC.B #CLK,&P1OUT
DEC R6
JNZ SENDLOOP
RET
ORG 0FFFEH
DW RESET
END#include "msp430x41x.h"
DIN EQU 001H ;P1.0
CLK EQU 002H ;P1.1
LOAD EQU 004H ;P1.2
ORG 0F000H
MOV #300H,SP ;初始化
MOV #WDTPW+WDTHOLD,&WDTCTL
BIS.B #CLK,&P1DIR
BIS.B #DIN,&P1DIR
BIS.B #LOAD,&P1DIR
PUSH #00C01H ;設(shè)置工作模式
BIC.B #LOAD,&P1OUT
CALL #MOVE
BIS.B #LOAD,&P1OUT
PUSH #00B05H ;設(shè)置掃描位數(shù)
BIC.B #LOAD,&P1OUT
CALL #MOVE
BIS.B #LOAD,&P1OUT
PUSH #009FFH ;設(shè)置編碼方式
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00A07H ;設(shè)置亮度
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
XIAN PUSH #00107H ;顯示第一位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00206H ;顯示第二位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00305H ;顯示第三位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00404H ;顯示第四位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00503H ;顯示第五位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
PUSH #00602H ;顯示第六位
BIC.B #LOAD,&P1OUT
CALL MOVE
BIS.B #LOAD,&P1OUT
JMP $
MOVE MOV.B #16,R6
POP R13
MOV #1,R10
SENDLOOP BIC.B #CLK,&P1OUT
BIT R10,R13
JNZ SEND1
SEND0 BIC.B #DIN,&P1OUT
JMP GOON
SEND1 BIS.B #DIN,&P1OUT
GOON BIS.B #CLK,&P1OUT
RLA R10
BIC.B #CLK,&P1OUT
DEC R6
JNZ SENDLOOP
RET
END
MAX7219的c程序
/*---------------------------------------------------------
?*?????????????????????程序說明???????????????????????????*
?*?1、本程序已經(jīng)通過測試,非常好用;??????????????????????*
?*?2、在非譯碼方式下編碼和一般書上寫的不一樣,請注意;????*
?*?3、每次送顯示的時候先初始化一次;??????????????????????*
?*?4、在設(shè)計電路或制作試驗板時注意添加Vcc到GND之間的電容,*
?*????一個10vF的電解電容和0.1vF的陶瓷電容。并在DIN、LOAD、*
?*????CLK到GND之間接入30pF的瓷片電容。????????????????????*
?*????????????????????????????????????????????????????????*
?*????????????????程序提供人:蘇建宇??????????????????????*
?*????????????????????????????????????????????????????????*
?*????????????????????????????????????????????????????????*
----------------------------------------------------------*/
#include?
#include?
//#include?
/*--------------------------------------------------*/
sbit?dis_DIN=P1^0;???????????/*顯示串行數(shù)據(jù)輸入端*/
sbit?dis_LOAD=P1^1;??????????/*顯示數(shù)據(jù)鎖存端*/
sbit?dis_CLK=P1^2;???????????/*顯示時鐘輸入端*/
#define?NoOp???0x00?????????/*空操作*/
#define?Digit0?0x01?????????/*數(shù)碼管1*/
#define?Digit1?0x02?????????/*數(shù)碼管2*/
#define?Digit2?0x03?????????/*數(shù)碼管3*/
#define?Digit3?0x04?????????/*數(shù)碼管4*/
#define?Digit4?0x05?????????/*數(shù)碼管5*/
#define?Digit5?0x06?????????/*數(shù)碼管6*/
#define?Digit6?0x07?????????/*數(shù)碼管7*/
#define?Digit7?0x08?????????/*數(shù)碼管8*/
#define?DecodeMode?0x09?????/*譯碼模式*/
#define?Intensity?0x0a?????/*亮度*/
#define?ScanLimit?0x0b??????/*掃描界限*/
#define?ShutDown?0x0c???????/*掉電模式*/
#define?DisplayTest?0x0f????/*顯示測試*/
#define?ShutdownMode?0x00??????/*掉電方式工作*/
#define?NormalOperation?0x01???/*正常操作方式*/
#define?DecodeDigit?0xff???????/*譯碼位數(shù)設(shè)置*/
#define?IntensityGrade?0x0a????/*顯示亮度級別設(shè)置*/
#define?ScanDigit?0x07?????????/*掃描位數(shù)設(shè)置*/
#define?TestMode?0x01??????????/*顯示測試方式*/
#define?TextEnd?0x00???????????/*顯示測試結(jié)束,正常工作*/
unsigned?char?data?DisBuffer[8]={0,0,0,0,0,0,0,0};????/*顯示緩存區(qū)*/
unsigned?char?code?dispaly_list[]=
????{?
0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b,????/*0,1,2,3,4,5,6,7,8,9*/
??????0x77,0x1f,0x4e,0x3d,0x4f,0x47,0x67,0x3e,0xff,0x00};???/*A,B,C,D,E,F,P,U,全
亮,全滅*/
/*--------------------------------------------------------
???????????????????10ms延時子程序
---------------------------------------------------------*/
void?delayX10ms(unsigned?char?count)
?????{
??????unsigned?char?j,k;
??????while(count--!=0)
????????{
?????????for(j=0;j<43;j++)
???????????for(k=0;k<73;k++)
???????????;
????????}
?????}
/*-------------------------------------------------
????????????????向MAX7219寫入字節(jié)(8位)
--------------------------------------------------*/
void?SendChar?(unsigned?char?ch)
???{
????unsigned?char?i,temp;
????_nop_();
????for?(i=0;i<8;i++)
???????{
???????????temp=ch&0x80;
???????????ch=ch<<1;
???????????if(temp)
??????????{
???????????dis_DIN=1;
???????????dis_CLK=0;
???????????dis_CLK=1;
??????????}
????????else
??????????{
???????????dis_DIN=0;
???????????dis_CLK=0;
???????????dis_CLK=1;
??????????}
???????}
???}
/*-------------------------------------------------
???????????????向MAX7219寫入字(16位)
-------------------------------------------------*/
void?WriteWord?(unsigned?char?addr,unsigned?char?num)
???{
????dis_LOAD=0;
????_nop_();
????SendChar?(addr);
????_nop_();
????SendChar?(num);
????_nop_();
????dis_LOAD=1;
???}
/*-------------------------------------------------
?????????????????MAX7219初始化
-------------------------------------------------*/
void?InitDis?(void)
???{
????WriteWord?(ScanLimit,ScanDigit);?????????/*設(shè)置掃描界限*/
????WriteWord?(DecodeMode,DecodeDigit);??????/*設(shè)置譯碼模式*/
????WriteWord?(Intensity,IntensityGrade);????/*設(shè)置亮度*/
????WriteWord?(ShutDown,NormalOperation);????/*設(shè)置電源工作模式*/
???}
/*-------------------------------------------------
????????????????????系統(tǒng)上電初始化
-------------------------------------------------*/
void?InitMain?(void)
???{
????IE=0x00;????/*設(shè)置中斷允許寄存器*/
????IP=0x00;????/*設(shè)置中斷優(yōu)先級管理寄存器*/
????TH0=0xd8;???/*設(shè)定時器初值,10ms*/
????TL0=0xf0;
????TMOD=0x01;??/*T1?定時器模式2,波特率發(fā)生器,T0?定時器模式1*/
????TCON=0x11;??/*設(shè)置定時器控制寄存器,INT0設(shè)置為邊沿觸發(fā)方式*/
????PSW=0x00;
???}
/*-------------------------------------------------
????????????????????主函數(shù)
-------------------------------------------------*/
void?main(void)
??{
???InitMain?();
???InitDis?();
???WriteWord?(DisplayTest,TestMode);
??????delayX10ms(0x64);
???????delayX10ms(0x64);
???WriteWord?(DisplayTest,TextEnd);
????while(1)
????????????{
?????????????unsigned?char?i;
?????????????for?(i=0;i<=9;i++)
????????????????{
???????????????delayX10ms(0x64);
???????????????delayX10ms(0x64);
?????????????????InitDis?();
???????????????DisBuffer[0]=i;
???????????????DisBuffer[1]=i;
???????????????DisBuffer[2]=i;
???????????????DisBuffer[3]=i;
???????????????DisBuffer[4]=i;
???????????????DisBuffer[5]=i;
???????????????DisBuffer[6]=i;
???????????????DisBuffer[7]=i;
???????????????
???????????????WriteWord?(Digit0,DisBuffer[0]);
???????????????WriteWord?(Digit1,DisBuffer[1]);
???????????????WriteWord?(Digit2,DisBuffer[2]);
???????????????WriteWord?(Digit3,DisBuffer[3]);
???????????????WriteWord?(Digit4,DisBuffer[4]);
???????????????WriteWord?(Digit5,DisBuffer[5]);
???????????????WriteWord?(Digit6,DisBuffer[6]);
???????????????WriteWord?(Digit7,DisBuffer[7]);
??????????????}
??????????}
???}
- 我正好有個7219,一直想學(xué)一下,51節(jié)就搭個電路看看,謝謝。 [電烙鐵] 2005-4-22?18:00:21
- 我有更簡單的 [rq88] 2005-4-22?18:38:00
我有更簡單的
- 那就發(fā)上來大家都看看嘛? [bush636] 2005-4-22?21:19:13
- 我有AVR?C++的?AT90S2313通過(有圖)(附圖) [Sunnyyonkers] 2005-4-23?14:27:58
要注意到時序正確就行了,另外電壓一定要夠,否則一定會出現(xiàn)亂
碼。
我先給出一個我做的一個通用驅(qū)動。
//------------------------------------------------------------------------------
//Author:SunnyYonkers
//Date:?2005y-03m-18d?13:00
//------------------------------------------------------------------------------
#include?
#include?
#include?
#include?
#include?
#include?
#include?
//------------------------------------------------------------------------------
//Hardware?Define
//引腳定義
#define?SOFT_SERIAL_PORT??PORTB
#define?SOFT_SERIAL_DDR???DDRB
#define?SOFT_SERIAL_PIN???PINB
//------------------------------------------------------------------------------
#define?LOAD_PIN??????????0b00000100
#define?DIN_PIN???????????0b00001000
#define?CLK_PIN???????????0b00010000
//------------------------------------------------------------------------------
//定義引腳操作
#define?SET_DIN???????????SOFT_SERIAL_PORT?|=?DIN_PIN
#define?CLR_DIN???????????SOFT_SERIAL_PORT?&=?~DIN_PIN??
#define?SET_CLK???????????SOFT_SERIAL_PORT?|=?CLK_PIN
#define?CLR_CLK???????????SOFT_SERIAL_PORT?&=?~CLK_PIN??
#define?SET_LOAD??????????SOFT_SERIAL_PORT?|=?LOAD_PIN
#define?CLR_LOAD??????????SOFT_SERIAL_PORT?&=?~LOAD_PIN??
//------------------------------------------------------------------------------
#define?TRUE??????????????0x01
#define?FALSE?????????????0x00
//------------------------------------------------------------------------------
#define?DISPLAY_ADD_0?????0x01
#define?DISPLAY_ADD_1?????0x02
#define?DISPLAY_ADD_2?????0x03
#define?DISPLAY_ADD_3?????0x04
#define?DISPLAY_ADD_4?????0x05
#define?DISPLAY_ADD_5?????0x06
#define?DISPLAY_ADD_6?????0x07
#define?DISPLAY_ADD_7?????0x08
//------------------------------------------------------------------------------
#define?DECODE_ADDRESS????0x09
#define?LIGHT_ADDRESS?????0x0a
#define?SCAN_WIDE?????????0x0b
#define?SLEEP_ADDRESS?????0x0c
#define?TEST_ADDRESS??????0x0d??
//------------------------------------------------------------------------------
#define?SLEEP_MODE????????0x00
#define?UN_SLEEP_MODE?????0x01
//------------------------------------------------------------------------------
#define?NO_DECODE?????????0x00
#define?DECODE_0_?????????0x01
#define?HALF_DECODE???????0x0f
#define?DECODE_ALL????????0xff?
//------------------------------------------------------------------------------
#define?_CHAR_0????????????0b00000000
#define?_CHAR_1????????????0b00000001
#define?_CHAR_2????????????0b00000010
#define?_CHAR_3????????????0b00000011
#define?_CHAR_4????????????0b00000100
#define?_CHAR_5????????????0b00000101
#define?_CHAR_6????????????0b00000110
#define?_CHAR_7????????????0b00000111
#define?_CHAR_8????????????0b00001000
#define?_CHAR_9????????????0b00001001
#define?_CHAR_-????????????0b00001010
#define?_CHAR_E????????????0b00001011
#define?_CHAR_H????????????0b00001100
#define?_CHAR_L????????????0b00001101
#define?_CHAR_P????????????0b00001110
#define?_NO_CHAR???????????0b00001111
#define?_DOT???????????????0b10000000
//------------------------------------------------------------------------------
class?max7219drv?
{
????public:
????????max7219drv();
????private:????????
????????void?write(unsigned?char?cData);
????public:
????????void?send(unsigned?char?address,unsigned?char?ndata);
};
//------------------------------------------------------------------------------
//構(gòu)造函數(shù)
max7219drv::max7219drv()
{
????SOFT_SERIAL_PORT?|=?0b11111111;//初始狀態(tài)高電平????
????SOFT_SERIAL_DDR??|=?0b11111111;//狀態(tài)
????///////////////////////////////////////////////
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//寫數(shù)據(jù)微程序:私有
void?max7219drv::write(unsigned?char?cData)
{
????unsigned?char?nloop=0x07;
????/////////////////////////////////////////////????
????do{
????????(0x80?&?cData)???(SET_DIN)?:?(CLR_DIN);cData<<=1;//數(shù)據(jù)移
出
????????CLR_CLK;
????????SET_CLK;//產(chǎn)生一個時鐘信號
????}while(nloop--);
}
//------------------------------------------------------------------------------
//寫數(shù)據(jù)子程序:公有
void?max7219drv::send(unsigned?char?address,unsigned?char?ndata)
{
????write(address);
????write(ndata);????????
????CLR_LOAD;????
????SET_LOAD;
}
//------------------------------------------------------------------------------
int?main(void)
{
????max7219drv?drv;
????/////////////////////////////////////////////////////////////////
????for(;;)
????{
????
????/////////////////////////////////////////////////////////////
????????//Init?MAX7219
????????drv.send(SLEEP_ADDRESS,UN_SLEEP_MODE);????
????????drv.send(SCAN_WIDE,0x07);
????????drv.send(LIGHT_ADDRESS,0xf9);
????????drv.send(DECODE_ADDRESS,DECODE_ALL);
????
????/////////////////////////////////////////////////////////////
????????drv.send(DISPLAY_ADD_0,_CHAR_1?|?_DOT);
????????drv.send(DISPLAY_ADD_1,_CHAR_2?|?_DOT);
????????drv.send(DISPLAY_ADD_2,_CHAR_3?|?_DOT);
????????drv.send(DISPLAY_ADD_3,_CHAR_4?|?_DOT);
????????drv.send(DISPLAY_ADD_4,_CHAR_5?|?_DOT);
????????drv.send(DISPLAY_ADD_5,_CHAR_6?|?_DOT);
????????drv.send(DISPLAY_ADD_6,_CHAR_7?|?_DOT);
????????drv.send(DISPLAY_ADD_7,_CHAR_8?|?_DOT);
????
????/////////////////////////////////////////////////////////////
????????//去掉小數(shù)點使用?????drv.send(DISPLAY_ADD_7,_CHAR_8?&~?
_DOT);
????????//添加小數(shù)點使用?????drv.send(DISPLAY_ADD_7,_CHAR_8?|??
_DOT);
????
????/////////////////////////////////////////////////////////////????
????
????}
????return?0;
}
//------------------------------------------------------------------------------
評論
查看更多