Beruflich Dokumente
Kultur Dokumente
h>
#include "pic24_all.h"
//#include "pic24_util.h"
//#include "pic24_delay.h"
//config bits
_FBS(BWRP_WRPROTECT_OFF);
_FGS(GSS_OFF & GCP_OFF & GWRP_OFF);
_FOSCSEL(FNOSC_PRIPLL & IESO_OFF);
_FOSC(FCKSM_CSDCMD & IOL1WAY_OFF & OSCIOFNC_ON & POSCMD_HS );//High speed external
crystal
_FWDT(FWDTEN_OFF);
_FPOR(FPWRT_PWR1);
#define NUM_TLCS 12 //how many TLCs in serial, this is taken from the arduino
tlc library
#define NUM_ROWS 8 //how many multiplexed rows, this is not currently
implemented here.
int dummy_spi_read; //SPI buffer must be read not to cause overflow even if no data
is received.
//volatile int count=0;
//SPI functions
static inline void shiftRow(unsigned char row);
static void shift16(int byte);
init();
spiinit();
int ch;
int a;
int b;
set_all(0);
while(1)
{
//test pattern
int a =0;
for (a=0; a<8; a+=1)
{//set_all(0);
a_delay(600); a_delay(600);
}
}
}//main
void init(void)
{
/* Oscillator clock config */
OSCCONbits.LPOSCEN = 0; //2nd osc off
OSCCONbits.CF = 0; //clock fail off
OSCCONbits.NOSC = 0b011; //HS w PLL
OC1RS = 1; // Load the Compare Register Value for falling edge gsclk output
//Initialize Output Compare Module 2, blank and xlat fire immediately before
interrupt
OC2CONbits.OCM = 0b000; // Disable Output Compare Module
OC2CONbits.OCTSEL = 1; // Select Timer 3 as output compare time base
//OC2R = 4094;
OC2R = 8189;
//OC2RS = 16380;
//OC2RS = 4095;
OC2RS = 8190;
//OC2RS = 16380;
void spiinit(void)
{
}//spiinit
if (!isShifting)
{
//asm( "nop");
//PORTB = 0b11111111;
PORTB = 0b00000000;
//asm( "nop");
//a_delay(1);
PORTA ^= 0x01;
//PORTB = 0b11111111;
shiftRow(row);
//row = 0;
//PORTB = 0b11111111;
RPOR7bits.RP14R = 0b10011; // tie rp14 back to oc2
//PORTB = 0b11111111;
PORTB = row_enable[row];
row++;
isShifting = 0;
if (row == (NUM_ROWS))
{
row = 0;
// PORTA ^= 0x01;
}
}//if isShifting
}//ISR T3 interrupt
static inline void shiftRow(unsigned char row) //4 tlc values sent in 3 16 bit SPI
sends
{
int *p = display_array[row];
int * const end = p + NUM_TLCS * 16;
while (p < end)
{
unsigned int a = *p++;
unsigned int b = *p++;
unsigned int c = *p++;
unsigned int d = *p++;
shift16((a << 4) | (b >> 8));
shift16((b << 8) | (c >> 4));
shift16((c << 12) | d);
}//while
}//shiftROW
static void set(unsigned char row, unsigned char channel, int value) //very
simple!
{
}//set
}//set
}//set