|
Another early project with the dsPIC 30F4013. SPI out to my MAX7219 display board. Written in C for MPLAB C30.
 Here's the schematic. Click on it to see it full size.
The code: #include "p30f4013.h"
_FOSC(FRC) //osc _FWDT(WDT_OFF) _FBORPOR(MCLR_EN & PWRT_OFF) //MCLR enable & power-up timers off
int spiout(int); void delay(void); void beep(int);
#define CS _LATD8 #define piezo _LATC13
int main(void) { int x; char y; ADPCFG = 0xffff; //all digital TRISC = TRISD = TRISF = 0; SPI1CON = 0x073f; SPI1STATbits.SPIEN = 1;
beep(80); spiout(0x0a0f); //intensity register to full bright spiout(0x0b03); //scan limit register - display digits 0-3 spiout(0x090f); //decode mode register - code B spiout(0x0c01); //shutdown register - normal
while(1) { for(x=0;x<10000;x++) //display 0-9999 { spiout(0x0100+x); spiout(0x0200+x); spiout(0x0300+x); spiout(0x0400+x); delay(); } spiout(0x010c); //display HELP spiout(0x020b); spiout(0x030d); spiout(0x040e); delay(); for(y=0;y<16;y++) //cycle thru intensity levels { spiout(0x0a00+y); beep(70); delay(); } } return 0; }
int spiout(int send) { CS = 0; //CS low SPI1BUF = send; while(!SPI1STATbits.SPIRBF){} CS = 1; return SPI1BUF; }
void beep(int tone) { int x,y; for(x=0;x<80;x++) { piezo = 1; for(y=0;y<tone;y++){} piezo = 0; for(y=0;y<tone;y++){} } }
void delay(void) { int x,y; for(x=0;x<30;x++) { for(y=0;y<10000;y++){} } } |