Any idea why CW thinks a } is missing at the line with the larger font?
Thanks
Dan
#include <hidef.h> // common defines and macros */
#include "derivative.h" // derivative-specific definitions */
#include "stdio.h"
#include "float.h"
#define SPI_isr 0xFFDE
#define ATDCH 0x08 // select ATD ch
#define SW2 PTP_PTP3
#define SW3 PTP_PTP2
#define SW4 PTP_PTP1
#define SW5 PTP_PTP0
#define PBSW PTP |= 0xF0 // PBSW status in PTP low nibble
#define DPSW1 PORTB_PB7
#define DPSW2 PORTB_PB6
#define DPSW3 PORTB_PB5
#define DPSW4 PORTB_PB4
#define DPSW5 PORTB_PB3
#define DPSW6 PORTB_PB2
#define DPSW7 PORTB_PB1
#define DPSW8 PORTB_PB0
#define DPSW PORTB
#define LED1 PORTA_PA0 // LED1 assigned to D9
#define LED2 PORTA_PA1
#define LED3 PORTA_PA2
#define LED4 PORTA_PA3
#define LED5 PORTA_PA4
#define LED6 PORTA_PA5
#define LED7 PORTA_PA6
#define LED8 PORTA_PA7 // LED8 assigned to D2
#define LEDS PORTA
void main(void) {
//DisableInterrupts;
PORTA = 0xFF; // init porta, all leds off
DDRA = 0xFF; // porta output
PTP = 0xFF; // init portp
DDRP = 0xF0; // ptp[3:0] input
PERP = 0x0F; // enable pulls
PPSP = 0x00; // pull-downs
PIFP = 0xFF; // clr spurious flags
PORTB = 0x00; // init PORTB
DDRB = 0x10; // PORTB input
PUCR_PUPBE = 1; // PORTB pull enable
//PTS = 0xFF; // port S data default
DDRS = 0x10; // PortS DDR default
REFDV = 0x40; // XTAL=4MHz
// Make sure we use the Xtal Oscillator
//CLKSEL &= 0x7F;
// Set Sys Clock to 32MHz by enabling PLL with a 4MHz Xtal
//SYNR = 0x07;
//REFDV = 0;
// Enable the PLL
//PLLCTL |= 0x40;
// Wait until the PLL is stable
//while(!(CRGFLG & 0x08));
// Set PLL as Clock source, keep SYSCLK running in wait mode
//CLKSEL = 0x80;
/* SPI0BR: ??=0,SPPR2=0,SPPR1=0,SPPR0=0,??=0,SPR2=1,SPR1=1,SPR0=0 */
//SPI0BR = 0x06; // Baud = bus clock / 128
/* SPI0CR1: SPIE=0,SPE=1,SPTIE=0,MSTR=0,CPOL=0,CPHA=1,SSOE=0,LSBFE=0 */
SPI0CR1 = 0x44; // Enable SPI as Slave, SS out auto
/* SPI0CR2: ??=0,XFRW=0,??=0,MODFEN=0,BIDIROE=0,??=0,SPISWAI=0,SPC0=0 */
SPI0CR2 = 0x00; // prep Master Mode
long outputCode;
double voltage;
unsigned char adcCode[5];
PORTB = 0x10;
while(!(PTS_PTS7))
adcCode[0] = 0;
adcCode[1] = 0;
adcCode[2] = 0;
adcCode[3] = 0;
adcCode[4] = 0;
PORTB = 0x00;
while(!(SPI0SR_SPIF)); // wait for SPI transmit ready
adcCode[0] = SPI0DRL;
while(!(SPI0SR_SPIF)); // wait for SPI transmit ready
adcCode[1] = SPI0DRL;
while(!(SPI0SR_SPIF)); // wait for SPI transmit ready
adcCode[2] = SPI0DRL;
while(!(SPI0SR_SPIF)); // wait for SPI transmit ready
adcCode[3] = SPI0DRL;
while(!(SPI0SR_SPIF)); // wait for SPI transmit ready
adcCode[4] = SPI0DRL;
//outputCode = (((0xFF & 0x80) ? (0xFFL) : (0x00L)) << 16);
outputCode = (long)(((((adcCode[2] & 0x80) ? (0xFFL) : (0x00L)) ) << 24)|((adcCode[2] & 0xFFL) << 16)|((adcCode[3] & 0xFFL) << 8)|((adcCode[4] & 0xFFL) << 0));
voltage = outputCode * .0000004883;
for(;;) {
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}