Hello, I am working on an embedded project involving the ADuC845 micro and the MAX7221. I am using the Keil development tools as my IDE for this project. The interface between the ADuC845 and the MAX7221 is SPI. The ADuC845 is configured as the master and the MAX7221 is the slave.
When I test the AduC845 SPI interrupt ,It can work well. the code as below:
#include <Aduc845.h> sbit LED = P3^6; void InitPLL() { CFG845 = 0x81; // enable extended sp, XRAM enable PLLCON = 0x00; // Fosc = 12.582912MHz while (!(PLLCON & 0x40)); } void InitSPI() { SPE = 1; SPIM = 1; CPOL = 0; CPHA = 0; SPR1 = 1; SPR0 = 1; IEIP2=0x11; EA = 1; } void main(void) { unsigned int i; InitPLL(); InitSPI(); LED ^= 1; while(1) { SPIDAT = 0x01; for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); } } void SPI_I2C_ISR() interrupt 7 //SPI,IIC中断 { if(ISPI) { LED ^= 1; ISPI = 0; } }
When I use the code to drive MAX7221,It can't work. the code as below:
#include <Aduc845.h> #include <intrins.h> sbit nCS = P2^7; // CS for Max7221 sbit LED = P3^6; // 0-F,P,-,No, without dot code unsigned char seg7[19]={0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7B,0x77,0x1F,0x4E,0x3D,0x4F,0x47,0x67,0x01,0x00}; void InitPLL() { CFG845 = 0x81; // enable extended sp, XRAM enable PLLCON = 0x00; // Fosc = 12.582912MHz while (!(PLLCON & 0x40)); } void InitSPI() { SPE = 1; SPIM = 1; CPOL = 0; CPHA = 0; SPR1 = 1; SPR0 = 1; IEIP2=0x11; EA = 1; } void Write_Max7221(unsigned char dat) { nCS = 0; SPIDAT = dat; nCS = 1; } void InitMax7221() { nCS = 0; Write_Max7221(0x09); // decode mode = no decode Write_Max7221(0x00); // No decode for digits 7-0 nCS = 1; nCS = 0; Write_Max7221(0x0A); // intensity = 8/16 Write_Max7221(0x07); // nCS = 1; nCS = 0; Write_Max7221(0x0B); // scan limit =digit 0-3 Write_Max7221(0x03); // nCS = 1; nCS = 0; Write_Max7221(0x0C); // Shutdown Mode = Normal Operation Write_Max7221(0x01); // nCS = 1; } void main(void) { unsigned int i; unsigned char j; InitPLL(); InitSPI(); InitMax7221(); LED ^= 1; j=0; while(1) { Write_Max7221(1); Write_Max7221(seg7[j]); Write_Max7221(2); Write_Max7221(seg7[j]); Write_Max7221(3); Write_Max7221(seg7[j]); Write_Max7221(4); Write_Max7221(seg7[j]); j++; if(j>18) j=0; for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); for(i=60000;i>0;i--); } } void SPI_I2C_ISR() interrupt 7 //SPI,IIC中断 { if(ISPI) { LED ^= 1; ISPI = 0; } }