After lots of help from people, I've got some
working code:
1. Using a
PIC18F46K22 on an Olimex 40 pin board with three Futurlec 7 segment displays.
2. The code uses interrupts to look for RS232 or SPI messages and displays the results on one of the 7 segment displays.
3. The driving message is either RS232 or SPI and uses the Printout function. Two examples:
Printout(UART1_Write,"SHOW0%.3e\r",fd); // SHOW 1234567.1 on display 0
Printout(SPI1_Write, "SHOW2%7.3f\r",fc); // SHOW 987.654 on display 2
Both RS232 and SPI messages must be terminated by a '\r' to let the interrupt know that the message has ended.
Files are attached:
.c and .h files for the displays.
.c file to drive/test the displays.
some drawing files of the wiring.
Things that you may find useful and want to copy from the code:
1. SPI_Init_Advanced() on the PIC18F46K22 is not straightforward and took some help from MikeoE Filip.
2. Interrupt code for SPI and RS232 messages.
3. Using code to find a header ('SHOW') and a terminator ('\r') in the message stream.
4. Driving the MAX7219 seven segment driver chip.
And - if you are an ace programmer and spot an easier to do this - please post your improvements here.
Code for display .h
Code: Select all
////////////////////////////////////////////////////////////////////////////////
// Project: Futurlec_Displays //
// File: Futurlec_Displays.h //
// Function: Display on 4 Futurlec 7 segment dusplays //
// Display uses MAX7219 driver using SPI //
// MCU: PIC1846K22 //
// Board: EasyPICv7 //
// Power: 5 Volts //
// Frequency: 32kHz //
// Compiler: mikroC PRO for PIC version 7.2.0 //
// Programmer: ICD3 or on-board //
// Author: WVL //
// Date: 10 Feb 2019 //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Displays driven by MAX7219 seven segment driver //
// The digits are numbered 0 to 7 but have addresses 1 to 8 //
// This code uses the address 1-8, not the digit number //
// Address 8 is the leftmost digit. Address 1 is the rightmost digit //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// DECODE Register Address 0x09 //
// 1 in register does decode, 0 by-passes //
// SCANLIMIT Register Address 0xB //
// 1 in register displays digit, 0 gives no display of digit //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Pin allocation PIC18(L)F46K22 64k Flash, 32768 Instructions, 3896 Data //
// Two SPI: //
// SDO1 RC5 SDO2 RD4 //
// SDI1 RC4 SDI2 RD1 //
// SCK1 RC3 SCK2 RD0 //
// LOAD0 RB0 Bottom display active on rising edge //
// LOAD1 RB1 Middle display //
// LOAD2 RB2 Top display //
// Maximum clock is 10MHz //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Defines //
#define CS0 LATB0_bit // bottom display //
#define CS1 LATB1_bit // data latched in on rising edge //
#define CS2 LATB2_bit // top display //
#define DECODE 0x09 // display digits data 00h to FFh to decode all //
#define BRIGHTNESS 0x0A // intensity data 00h to 0Fh for maximum //
#define SCANLIMIT 0x0B // digits shown data 00h to 07h for all //
#define SHUTDOWN 0x0C // on or off data 00h or 01h for ON //
#define ON 0x01 //
#define OFF 0x00 //
#define LED_OLIMEX LATA0_bit //
#define LED_RED LATA2_bit //
#define LED_GREEN LATA3_bit //
#define LED_YELLOW LATA4_bit //
#define LED_WHITE LATA5_bit //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Globals //
char instring[21] = "1234567890"; // loaded after header detected //
bit good_data; // set in RS232 or SPI2 interrupt, cleared in main //
char display_number = 0; // 0 to 2, always instring[0] //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Set initial conditions on all MAX7219 7 segment drivers //
void Max7219_InitAll(); //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Clear one 7 segment display using display address 1-8 //
// Bottom dusplay= 0. Middle = 1. Top = 2 //
void Segment_Clear(char chip_select); //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Clear all 7 segment display CS0-CS2 using display address 1-8 //
void Segment_ClearAll(); //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Show variables on 7 segment displays using SPI1 and CS=0 //
// Normal Printout() descriptors %d %u %f with width and precision //
// Decodes E,e,-,. as special cases. + signs not displayed //
// Requires all Printout() functions to be terminated with '\r' //
void SPI1_Putc0(char ascii); //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Show variables on 7 segment displays using SPI1 and CS=1 //
// Normal Printout() descriptors %d %u %f with width and precision //
// Decodes E,e,-,. as special cases. + signs not displayed //
// Requires all Printout() functions to be terminated with '\r' //
void SPI1_Putc1(char ascii); //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Show variables on 7 segment displays using SPI1 and CS=2 //
// Normal Printout() descriptors %d %u %f with width and precision //
// Decodes E,e,-,. as special cases. + signs not displayed //
// Requires all Printout() functions to be terminated with '\r' //
void SPI1_Putc2(char ascii); //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Show demo on all displays //
void Demo_Display(); //
////////////////////////////////////////////////////////////////////////////////
Code for displa .c
Code: Select all
////////////////////////////////////////////////////////////////////////////////
// Project: Futurlec_Displays //
// File: Futurlec_Displays.c //
// Function: Display on 4 Futurlec 7 segment displays //
// Display uses MAX7219 driver using SPI //
// MCU: PIC1846K22 //
// Board: EasyPICv7 //
// Power: 5 Volts //
// Frequency: 32kHz //
// Compiler: mikroC PRO for PIC version 7.2.0 //
// Programmer: ICD3 or on-board //
// Author: WVL //
// Date: 10 Feb 2019 //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Last notes //
// SPI now working - special file from forum downloaded to //
// C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for PIC\Uses\P18 //
////////////////////////////////////////////////////////////////////////////////
#include "Futurlec_Displays.h" // prototypes, definintions, globals
////////////////////////////////////////////////////////////////////////////////
// ISR for all HIGH priority interrupts to 0x0008. Low go to 0018h //
void high_priority_int() iv 0x0008 ics ICS_AUTO { //
// Test if UART1 has received a character. //
// Look for header SHOW and record until '\r' is received, set good_data //
// Re-set all variables if >20 characters are received before '\r' //
if(RC1IF_bit){ //
unsigned short rxtemp=0; // last character rx from base //
static unsigned short lock_state=0; // inc after good ID character //
static unsigned short x=0; // array counter //
static unsigned short got_id=0; // TRUE after all ID received //
// Writing '0' clears errors //
RCSTA1.OERR= 0; //
RCSTA1.FERR= 0; //
// Receive a character //
rxtemp = UART1_Read(); //
LED_RED = ~LED_RED; //
// Header has been received so start filling array //
if(got_id==1){ //
LED_GREEN = 1; //
instring[x] = rxtemp; //
x++; //
} //
// instring is 20 bytes+'\0' test for overflow //
if(x>20){ //
LED_RED = 0; //
LED_GREEN = 0; //
lock_state = 0; //
got_id = 0; //
good_data = 0; //
x = 0; //
} //
// Test if '\r' AND got_id received and terminate string with '\0' //
// If so, set LED_WHITE and good_data //
if(instring[x-1]=='\r' && got_id==1){ //
instring[x]='\0'; //
got_id = 0; //
x = 0; //
LED_RED = 0; //
LED_GREEN = 0; //
LED_WHITE = 1; //
good_data = 1; //
} //
// Search for id = 'SHOW' and if found set got_id //
if (rxtemp== 'S' && lock_state == 0)lock_state++; //
else if (rxtemp== 'H' && lock_state == 1)lock_state++; //
else if (rxtemp== 'O' && lock_state == 2)lock_state++; //
else if (rxtemp== 'W' && lock_state == 3)got_id = 1; //
else lock_state = 0; // id wrong so reset combination //
//
RC1IF_bit = 0; // clear interrupt flag //
} //
//
// Test if SSP2 has received a character. //
// Look for header SHOW and record until '\r' is received, set good_data //
// Re-set all variables if >20 characters are received before '\r' //
if(SSP2IF_bit){ //
char rxtemp=0; // last character rx from base //
static unsigned short lock_state=0; // inc after good ID character //
static unsigned short x=0; // array counter //
static unsigned short got_id=0; // TRUE after all ID received //
// Receive a character //
rxtemp = SSP2BUF; //
LED_RED = ~LED_RED; //
// Header has been received so start filling array //
if(got_id==1){ //
LED_GREEN = 1; //
instring[x] = rxtemp; //
x++; //
} //
// instring is 20 bytes+'\0' test for overflow //
if(x>20){ //
LED_RED = 0; //
LED_GREEN = 0; //
lock_state = 0; //
got_id = 0; //
good_data = 0; //
x = 0; //
} //
// Test if '\r' AND got_id received and terminate string with '\0' //
// If so, set LED_YELLOW and good_data //
if(instring[x-1]=='\r' && got_id==1){ //
instring[x]='\0'; //
got_id = 0; //
x = 0; //
LED_RED = 0; //
LED_GREEN = 0; //
LED_YELLOW = 1; //
good_data = 1; //
} //
// Search for id = 'SHOW' and if found set got_id //
if (rxtemp== 'S' && lock_state == 0)lock_state++; //
else if (rxtemp== 'H' && lock_state == 1)lock_state++; //
else if (rxtemp== 'O' && lock_state == 2)lock_state++; //
else if (rxtemp== 'W' && lock_state == 3)got_id = 1; //
else lock_state = 0; // id wrong so reset combination //
//
SSP2IF_bit = 0; // clear interrupt flag //
} //
} //
////////////////////////////////////////////////////////////////////////////////
void main() {
char x = 0;
// Ports and pins
ANSELA = 0b00000000; // 1=analog 0=digital
ANSELB = 0b00000000; // 1=analog 0=digital
ANSELC = 0b00000000; // 1=analog 0=digital
ANSELD = 0b00000000; // 1=analog 0=digital
ANSELE = 0b00000000; // 1=analog 0=digital
WPUB = 0b00000000; // pull up 1=enabled 0=disabled
TRISA = 0b00000000; // LEDs on RA0 and RA2 to RA5
TRISB = 0b00000000; // chip selects on RB0 to RB2
// SPI1 on PORTC is a MASTER
TRISC3_bit = 0; // op for SCK1 - used
TRISC4_bit = 1; // ip for SDI1 - unused
TRISC5_bit = 0; // op for SDO1 - used
// SPI2 on PORD is s SLAVE
TRISD0_bit = 1; // ip for SCK2 - used
TRISD1_bit = 1; // ip for SDI2 - used
TRISD3_bit = 1; // ip for SS2 - unused
TRISD4_bit = 0; // op for SDO2 - unused
// UART1 on PORTC
TRISC6_bit = 0; // op for UART1 - used
TRISC7_bit = 1; // ip for UART1 - used
LATA = 0;
LATB = 0;
LATC = 0;
LATD = 0;
LATE = 0;
// Peripherals
PMD1 = 0b00011111; // CCP1MD to CCP5MD off
UART1_Init(9600); // use RC6/Tx1 RC7/Rx1 not RD6/Tx2 RD7/Rx2 _SPI_CLK_IDLE_LOW
delay_ms(5);
UART1_Write_Text("EasyPICv7_Futurlec_Displays running at 20MHz\r\n");
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_LOW_2_HIGH);
SPI2_Init_Advanced(_SPI_SLAVE_SS_DIS,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_LOW_2_HIGH);
Max7219_InitAll();
Segment_ClearAll();
// Flash LEDs
for(x=0;x<10;x++){LATA = ~LATA;delay_ms(50);}
// Run demo
Demo_Display();
// Interrupts
RC1IP_bit = 1; // UART1 Rx is high priority
RC1IF_bit = 0; // CLEAR interrupt flag
RC1IE_bit = 1; // ENABLE U1Rx interrupt
SSP2IP_bit = 1; // SSP2 is high priority
SSP2IF_bit = 0; // CLEAR interrupt flag
SSP2IE_bit = 1; // ENABLE SSP2 interrupt
IPEN_bit = 1; // ENABLE interrupt prioroty
GIEH_bit = 1; // ENABLE all high priority ints
GIEL_bit = 1; // ENABLE all low priority ints
good_data = 0; // clear flag
while(1){
// If good_data, read instring
if(good_data){
// Read display number
display_number = instring[0];
x = 1;
if(display_number=='0'){
Segment_Clear(0);
while(instring[x] !='\0'){
SPI1_Putc0(instring[x]);
x++;
if(x>20)break;
}
}
if(display_number=='1'){
Segment_Clear(1);
while(instring[x] !='\0'){
SPI1_Putc1(instring[x]);
x++;
if(x>20)break;
}
}
if(display_number=='2'){
Segment_Clear(2);
while(instring[x] !='\0'){
SPI1_Putc2(instring[x]);
x++;
if(x>20)break;
}
}
good_data = 0;
LED_YELLOW = 0;
LED_WHITE = 0;
}
// Housekeeping
LED_OLIMEX = ~LED_OLIMEX;
Delay_ms(1);
}
}
////////////////////////////////////////////////////////////////////////////////
// Function - Set initial conditions on all MAX7219 7 segment drivers //
void Max7219_InitAll(){ //
LATB = 0b00000000; //
SPI1_Write(SHUTDOWN); SPI1_Write(ON); // on //
LATB = 0b00000111; //
LATB = 0b00000000; //
SPI1_Write(DECODE); SPI1_Write(0xFF); // decode all //
LATB = 0b00000111; //
LATB = 0b00000000; //
SPI1_Write(BRIGHTNESS); SPI1_Write(0x0F); // max //
LATB = 0b00000111; //
LATB = 0b00000000; //
SPI1_Write(SCANLIMIT); SPI1_Write(0x07); // show all //
LATB = 0b00000111; //
} //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Clear one 7 segment display using display address 1-8 //
// Bottom dusplay= 0. Middle = 1. Top = 2 //
void Segment_Clear(char chip_select){ //
char x = 0; //
for(x=1;x<=8;x++){ //
LATB = ~(1<<chip_select); // selected pin low, rest high //
SPI1_Write(x); //
SPI1_Write(0xF); //
LATB = 0b00000111; // all chip selects high //
} //
} //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Clear all 7 segment display CS0-CS2 using display address 1-8 //
void Segment_ClearAll(){ //
char x = 0; //
for(x=1;x<=8;x++){ //
LATB = 0b00000000; // selected pin low, rest high //
SPI1_Write(x); //
SPI1_Write(0xF); //
LATB = 0b00000111; // all chip selects high //
} //
} //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Show variables on 7 segment displays using SPI1 and CS=0 //
// Normal Printout() descriptors %d %u %f with width and precision //
// Decodes E,e,-,. as special cases. + signs not displayed //
// Requires all Printout() functions to be terminated with '\r' //
void SPI1_Putc0(char ascii){ //
char display = 0; // set to display a character //
static char x = 8; // x is digit address, 8 is leftmost //
static old_byte = 0; // last byte already displayed //
char byte = ascii-48; // convert ASCII to digit //
if(ascii=='+'){ // test for '+' signs //
display = 0; // don't display //
} //
if(ascii=='E'||ascii=='e'){ // test for 'e' or 'E' //
byte = 0x0B; // E in MAX7219 decode //
display = 1; // display 'E' //
} //
if(ascii=='-'){ // test for '-' //
byte = 0x0A; // - in MAX7219 decode //
display = 1; // display '-' //
} //
if(isdigit(ascii)){ // test for digits 0 to 9 //
old_byte=byte; // in case next character is '.' //
display = 1; // display digits 0-9 //
} //
if(ascii=='.'){ // test for a '.' //
byte = old_byte|0x80; // add decimal point 0x80 to old byte //
x++; // move back 1 address to the left //
display = 1; // display '.' with previous digit //
} //
if(ascii=='\r'){ // test for termination '\r' //
x=8; // leftmost digit //
old_byte=0; //
display =0; //
} //
// Write byte to address X if display has been set //
if(display){ //
CS0 = 0; // active low //
SPI1_Write(x); // digit address 8=left, 1=right //
SPI1_Write(byte); // byte to be displayed //
CS0 = 1; // deselect //
x--; // move address to the right //
display = 0; // clear the flag //
} //
return; //
} //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Show variables on 7 segment displays using SPI1 and CS=1 //
// Normal Printout() descriptors %d %u %f with width and precision //
// Decodes E,e,-,. as special cases. + signs not displayed //
// Requires all Printout() functions to be terminated with '\r' //
void SPI1_Putc1(char ascii){ //
char display = 0; // set to display a character //
static char x = 8; // x is digit address, 8 is leftmost //
static old_byte = 0; // last byte already displayed //
char byte = ascii-48; // convert ASCII to digit //
if(ascii=='+'){ // test for '+' signs //
display = 0; // don't display //
} //
if(ascii=='E'||ascii=='e'){ // test for 'e' or 'E' //
byte = 0x0B; // E in MAX7219 decode //
display = 1; // display 'E' //
} //
if(ascii=='-'){ // test for '-' //
byte = 0x0A; // - in MAX7219 decode //
display = 1; // display '-' //
} //
if(isdigit(ascii)){ // test for digits 0 to 9 //
old_byte=byte; // in case next character is '.' //
display = 1; // display digits 0-9 //
} //
if(ascii=='.'){ // test for a '.' //
byte = old_byte|0x80; // add decimal point 0x80 to old byte //
x++; // move back 1 address to the left //
display = 1; // display '.' with previous digit //
} //
if(ascii=='\r'){ // test for termination '\r' //
x=8; // leftmost digit //
old_byte=0; //
display =0; //
} //
// Write byte to address X if display has been set //
if(display){ //
CS1 = 0; // active low //
SPI1_Write(x); // digit address 8=left, 1=right //
SPI1_Write(byte); // byte to be displayed //
CS1 = 1; // deselect //
x--; // move address to the right //
display = 0; // clear the flag //
} //
return; //
} //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Show variables on 7 segment displays using SPI1 and CS=2 //
// Normal Printout() descriptors %d %u %f with width and precision //
// Decodes E,e,-,. as special cases. + signs not displayed //
// Requires all Printout() functions to be terminated with '\r' //
void SPI1_Putc2(char ascii){ //
char display = 0; // set to display a character //
static char x = 8; // x is digit address, 8 is leftmost //
static old_byte = 0; // last byte already displayed //
char byte = ascii-48; // convert ASCII to digit //
if(ascii=='+'){ // test for '+' signs //
display = 0; // don't display //
} //
if(ascii=='E'||ascii=='e'){ // test for 'e' or 'E' //
byte = 0x0B; // E in MAX7219 decode //
display = 1; // display 'E' //
} //
if(ascii=='-'){ // test for '-' //
byte = 0x0A; // - in MAX7219 decode //
display = 1; // display '-' //
} //
if(isdigit(ascii)){ // test for digits 0 to 9 //
old_byte=byte; // in case next character is '.' //
display = 1; // display digits 0-9 //
} //
if(ascii=='.'){ // test for a '.' //
byte = old_byte|0x80; // add decimal point 0x80 to old byte //
x++; // move back 1 address to the left //
display = 1; // display '.' with previous digit //
} //
if(ascii=='\r'){ // test for termination '\r' //
x=8; // leftmost digit //
old_byte=0; //
display =0; //
} //
// Write byte to address X if display has been set //
if(display){ //
CS2 = 0; // active low //
SPI1_Write(x); // digit address 8=left, 1=right //
SPI1_Write(byte); // byte to be displayed //
CS2 = 1; // deselect //
x--; // move address to the right //
display = 0; // clear the flag //
} //
return; //
} //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function - Show demo on all displays //
void Demo_Display(){ //
char x = 0; //
// Write BILL LEGGE //
CS2 = 0;SPI1_Write(8);SPI1_Write(8); CS2 = 1; // B //
CS2 = 0;SPI1_Write(7);SPI1_Write(1); CS2 = 1; // I //
CS2 = 0;SPI1_Write(6);SPI1_Write(13);CS2 = 1; // L //
CS2 = 0;SPI1_Write(5);SPI1_Write(13);CS2 = 1; // L //
CS1 = 0;SPI1_Write(8);SPI1_Write(13);CS1 = 1; // L //
CS1 = 0;SPI1_Write(7);SPI1_Write(11);CS1 = 1; // E //
CS1 = 0;SPI1_Write(6);SPI1_Write(6); CS1 = 1; // 6 //
CS1 = 0;SPI1_Write(5);SPI1_Write(6); CS1 = 1; // 6 //
CS1 = 0;SPI1_Write(4);SPI1_Write(11);CS1 = 1; // E //
delay_ms(1000); //
Segment_ClearAll(); //
// Ripple segment displays, x must be <=8 //
for(x=1;x<=8;x++){ //
CS0 = 0;SPI1_Write(x);SPI1_Write(x);CS0 = 1; // position,character //
CS1 = 0;SPI1_Write(x);SPI1_Write(x);CS1 = 1; // position,character //
CS2 = 0;SPI1_Write(x);SPI1_Write(x);CS2 = 1; // position,character //
delay_ms(50); //
} //
delay_ms(500); //
Segment_ClearAll(); //
for(x=8;x>=1;x--){ //
CS0 = 0;SPI1_Write(x);SPI1_Write(x);CS0 = 1; // position,character //
CS1 = 0;SPI1_Write(x);SPI1_Write(x);CS1 = 1; // position,character //
CS2 = 0;SPI1_Write(x);SPI1_Write(x);CS2 = 1; // position,character //
delay_ms(50); //
} //
delay_ms(5); //
Segment_ClearAll(); //
} //
////////////////////////////////////////////////////////////////////////////////
And a test file .c
Code: Select all
////////////////////////////////////////////////////////////////////////////////
// Project: Futurlec_Displays_Test //
// File: Futurlec_Displays_Test.c //
// Function: Display on 4 Futurlec 7 segment dusplays //
// Send test data to the Futurlec displays by RS232 //
// ... and SPI //
// MCU: PIC1846K22 //
// Board: EasyPICv7 //
// Power: 5 Volts //
// Frequency: 32kHz //
// Compiler: mikroC PRO for PIC version 7.2.0 //
// Programmer: ICD3 or on-board //
// Author: WVL //
// Date: 10 Feb 2019 //
////////////////////////////////////////////////////////////////////////////////
void main() {
char my_string[] = "%u\r";
char x = 0;
char c = 48; // ascii '0' test number
unsigned int ui = 1; // test number
signed int si = -12001; // test number
signed int sj = -1; // test number
float fa = 1.2345678; // test number
float fb = -0.000087654321; // test number
float fc = 987.654; // test number
float fd = 12345678.0; // test number
// Ports and pins
ANSELA = 0b00000000; // 1=analog 0=digital
ANSELB = 0b00000000; // 1=analog 0=digital
ANSELC = 0b00000000; // 1=analog 0=digital
ANSELD = 0b00000000; // 1=analog 0=digital
ANSELE = 0b00000000; // 1=analog 0=digital
WPUB = 0b00000000; // pull up 1=enabled 0=disabled
TRISA = 0b00000000; // RA0 is looping LED, RA5 is CS
TRISB = 0b00000000; //
TRISC3_bit = 0; // op for SCK1
TRISC4_bit = 1; // ip for SDI1
TRISC5_bit = 0; // op for SDO1
LATA = 0;
// Peripherals
PMD1 = 0b00011111; // disable all comparators
// Use RC6/Tx1 RC7/Rx1 not RD6/Tx2 RD7/Rx2
UART1_Init(9600);
// Use RC3/SCK1 RC4/SDI1 RC5/SDO1
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_LOW_2_HIGH);
delay_ms(5);
UART1_Write_Text("EasyPICv7_Futurlec_Displays_Test running at 8MHz\r\n");
while(1){
// By RS232 on UART1 RC6 and RC7
Printout(UART1_Write,"SHOW0%u\r",ui); // 1++
delay_ms(1000);
Printout(UART1_Write,"SHOW1%d\r",si); // -12001
delay_ms(1000);
Printout(UART1_Write,"SHOW2%d\r",sj); // -1
delay_ms(1000);
Printout(UART1_Write,"SHOW0%f\r",fa); // 1.2345678
delay_ms(1000);
Printout(UART1_Write,"SHOW1%.2e\r",fb); // -0.000087654321
delay_ms(1000);
Printout(UART1_Write,"SHOW2%7.3f\r",fc); // 987.654
delay_ms(1000);
Printout(UART1_Write,"SHOW0%.3e\r",fd); // 1234567.1
delay_ms(1000);
// By SPI1 on RC3 and RC4
Printout(SPI1_Write,"SHOW0%u\r",ui); // 1++
delay_ms(1000);
Printout(SPI1_Write,"SHOW1%d\r",si); // -12001
delay_ms(1000);
Printout(SPI1_Write,"SHOW2%d\r",sj); // -1
delay_ms(1000);
Printout(SPI1_Write,"SHOW0%f\r",fa); // 1.2345678
delay_ms(1000);
Printout(SPI1_Write,"SHOW1%.2e\r",fb); // -0.000087654321
delay_ms(1000);
Printout(SPI1_Write,"SHOW2%7.3f\r",fc); // 987.654
delay_ms(1000);
Printout(SPI1_Write,"SHOW0%.3e\r",fd); // 1234567.1
delay_ms(1000);
// Housekeeping
delay_ms(50);
LATA0_bit = ~LATA0_bit;
}
}
Good luck from Bill Legge in Australia