Code:
#ifndef JUNEBUG_DEV_BOARD_H
#define JUNEBUG_DEV_BOARD_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* JUNEBUG_DEV_BOARD_H */
/* Junebug dev board set ups, this file is called by junebug_dev_board.c and
sets up the junebug dev board for using the on board 18f1320*/
/*LEDS on june bug are charlie plexed, so one pin is held low while the other
isheld high to turn on*/
void LED1_ON(void); //ANNODE is RA0 pin 1. CATHODE is RA6 PIN 15
void LED1_OFF( void); // opposite of led1 on
// ADC peripheral prototypes
/* first VR1_ON will set port direction and anaologue on digital off
will also select chanel AN1*/
void VR1_ON (void); //
void ADC_ON(void); //Enable the ADC peripheral
void ADC_OFF(void); // Disable the ADC peripheral
void SELECT_VR1(void);// Junebug Pot 1 channel select VR1 sits on RA1 pin2
// on the 18f1320 chip
void SET_ADC_INTERNAL_REF(void); // Function to set ADC mod to use VDD & Vss as REF
void SET_ADC_EXTERNAL_REF(void); // Function to set ADV to use external voltage REF
Thats the .h
this is the .c
This compiles ok now, since I moved it into the .c file
Code:
#include "junebug_dev_board.h"
#include <p18f1320.h>
int READ_ADC(void);
//turns Led1 on, on the june bug as they are charliplexed
void LED1_ON(void)
{
TRISAbits.RA0 =0; //led1 ANODE RA0 set to output
TRISAbits.RA6 =0; //led1 CATHODE RA6 set to output
LATAbits.LATA6 =0; //LED1 cathode set low
LATAbits.LATA0 =1; //LED1 ANNode set high
}
//Function to turn LED1 off
void LED1_OFF(void)
{
LATAbits.LATA6 =0;
LATAbits.LATA0 =0;
}
/* Some function's for setting up and using the junebug ADC unti with the
* Pic18f1320 chip on the tutor board */
void ADC_ON(void)
{
ADCON0bits.ADON =1; //Enable the ADC peripheral
}
void ADC_OFF(void)
{
Nop();
ADCON0bits.ADON =0; // Disable the ADC peripheral
}
void SELECT_VR1(void) // Select channel AN1 for junebug VR1 RA1 pin2 of 18f1320
{ // so we need to select chanel 1 this is ADCON0
ADCON0bits.CHS0 =1; //bits 4-2 set chanel select. AN1 is 001
ADCON0bits.CHS1 =0;
ADCON0bits.CHS2 =0;
}
void SET_ADC_INTERNAL_REF(void)
{
ADCON0bits.VCFG0 =0; // Sets ADC to VDD & VSS as voltage REF
ADCON0bits.VCFG1 =0;
}
void SET_ADC_EXTERNAL_REF(void)
{
ADCON0bits.VCFG0 =1; // sets V- REF to RA2 AN2 pin 6
ADCON0bits.VCFG1 =1; // sets V+ REF to RA3 AN3 pin 7
}
void VR1_ON(void)
{
ADCON1bits.PCFG1=0; //Sets AN1 to anologue
TRISAbits.RA1=1; //Sets AN1 (RA1) To input
// ADCON2=0b10110101; breaks down as follows
ADCON2bits.ADCS0=1; //ADCS0-ADCS2 Sets ADC converson clock to FOSC/16
ADCON2bits.ADCS1=0;
ADCON2bits.ADCS2=1;
ADCON2bits.ACQT0=0; //ACQT0-ACQT2 set AQU time. 110 sets to 16 TAD
ADCON2bits.ACQT1=1;
ADCON2bits.ACQT2=1;
ADCON2bits.ADFM=1; //Result right justified (bit6 does nothing)
// Setting bit 7 (ADFM)to 0= left just
}
int READ_ADC(void)
{
return (((unsigned int)ADRESH)<<8)|(ADRESL);
}
It's just from the template's and copying a sample file, I am trying to get used to mplab X and multiple files. Before I have always put everything in the main file, but it gets too big and is awkward to find things in. I thought I woud start really simple by kind of following a template.
the syntax error only occurs when I put
int READ_ADC(void); into the .h file, the errors just says syntax error with a blue line under, when you click the blue line it takes you straight to that line, when I move it to .c and compile the error is gone.
Bit of a head scratcher
, still I guess its mistakes we learn most from
.
I am trying to resist diving straight into the LCD driver
, if I can get the basics right then it should be ok.
Also I tried it with Kiel for 8051 and it compiled fine with it in the .h, so not sure if its the new C18 or not