|
|
View previous topic :: View next topic |
Author |
Message |
Sage_EE
Joined: 23 Apr 2010 Posts: 5
|
Desperately Need assistance |
Posted: Fri Apr 23, 2010 5:50 pm |
|
|
I have been reading all of the links and suggestions associated with the following error and I have had absolutely no luck in compiling my code. I need this code to work for my senior design project and I do not have adequate skills to debug this code. I originally had registers.c included in the source code but I was using an extern function when I read that wouldn't work. So I simply added all of my registers to the TRTLfinalCode.c file.
Code: |
//TRTLfinalCode.c
#device .*=16 adc=10 ICD=TRUE
#include <18F14K50.H> //Identify Microcontroller
//#include<registers.c> //include registers file
// Set up Config Bits ex. WDT,JTAG...
#fuses HS,NOWDT,NOPROTECT,NOLVP,MCLR
// Use HS Oscillator (startup)
// No Watchdog Timer
// No Code Protect
//
// Use MCLR Pin as Reset..
//Enable Master Clear=MCLR
#include <math.h>
#use delay(clock=2000000) //Setup C-Code Oscillator Value
//#use fast_io(d) //Leave the State of Port-D (all bits)
//the same until changed, again
#use I2C(master, SCL=PIN_RB6, SDA=PIN_RB4)
#define captured 1
#define ON 1
#define OFF 0
#define true 1
#define reedSW1 PIN_RA0 // input1 to reed switch on door 1
#define reedSW2 PIN_RA1 // input2 to reed switch on door 2
#define LED1 PIN_RA4 //output pin 1
#define LED2 PIN_RA5 //output pin 2
#define LED3 PIN_RC6 //output pin 3
#define LED4 PIN_RC7 //output pin 4
#define C12OUT PIN_RC4 //Battery alert output pin to redLED (output of comparator)
// TrapNum in EEPROM of RTC
// NOP(); == Preform No Operation for one instruction Cycle
//RA0 and RA1 are configured using 00000011 (convert to hex) and they do not need a TRISA register bit
//RA4, if used for output needs a LATA bit and maybe a TRISA bit
void blinkLED(void);
void SetTime(void);
void Checktime(void);
// make suer you have all functions listed/defined here
// VARIABLES USED
int GotIt;
int RTCHour; //16-Bit Word Variable
void main(void)
{
TRISA = 0b00000000; //configure output for pins RA4 & RA5
TRISB = 0b00101000; //used for clock
TRISC = 0b00000000; //configure out for battery monitor for pins RC7, RC6 and RC4, TRISC must be cleared for comparator operation
// PORTx and LATx writes to the whole port at once, making the value written highs or lows on the respective pins
WPUA = 0b00000000; // no weak pull up
IOCA = 0b00110011; // interupt on change RA0,RA1,RA4
//insert registers here
ANSEL = 0b00000000; // disables digital input buffer for analog comparator input
REFCON0 = 0b11100000;
CM1CON0 = 0b11100101; //inverts polarity, low power, use comparator1,
CM2CON0 = 0b00000000; //disabled
CM2CON1 = 0b00100010; //MC1OUT( mirror copy of C1OUT), FVR routed to C12REF input, no hysteresis, output synchronus to rising edge of TMR1 clock
T1CON = 0b01001001; //Timer1 register
OSCCON = 0b11000110; //Oscillator Control Register, Device is running from the internal oscillator (HFINTOSC or LFINTOSC)
OSCCON2 = 0b00000111;
OSCTUNE = 0b01000000;
// initalize all registers
SetTime(); // if RTC not set, Set it
// setup_comparator(mode) //Enables and sets the analog comparator module.
//The options vary depending on the chip, please refer to the header file for details.
//Relevant Interrupts:
// INT_COMP //Interrupt fires on comparator detect. Some chips have more than one comparator unit, and hence more interrupts.
Begin:
CheckBatt();
while(reedSW1 == captured || reedSW2 == captured) // If animal Captured
{
//TrapNum = getenv(ID); // Returns the device ID (set by #ID)
//printf("Animal in Trap: ", TrapNum, "/n/r")
// if True is defined as true, it needs to stsy the same.
// the compiler is case sensitive...
GotIt = True;
CheckBatt();
Checktime(); // Reads RTC, If night, Stay there till day then return
blinkLED();
}//while animal in cage
goto Begin;
}//main loop
//never Exit
void CheckBatt(void)
{
if (C12OUT)
blinkLED();
while(1);
}//end CeckBatt
void blinkLED(void) //set up output pins which pins can we use???
{
// if you wee to use an LED driver such as an LF412 as a buffer you only need to use one output pin to go to the "+" terminal of the opamp.
//LED1
Output_high(LED1);
Output_high(LED2);
Output_high(LED3);
Output_high(LED4);
//LEDs = ON;
delay_ms(500);
Output_low(LED1);
Output_low(LED2);
Output_low(LED3);
Output_low(LED4);
//LED = OFF;
delay_ms(2000);
}//end blinkLED
void SetTime(void)
{
//This code sets proper status register 1 values
I2C_START(); //Start communication
I2C_WRITE(0x60); //Write to status 1 register on the RTC. Info about this register on page 12 & 9, RTC datasheet.
I2C_WRITE(0xC0); //Initiate RTC and set to military time
I2C_STOP(); //End communication
//This code sets proper status register 2 values
I2C_START(); //Start communication
I2C_WRITE(0x62); //Write to status 2 register on the RTC. Info about this register on page 13 & 9, RTC datasheet.
I2C_WRITE(0x00); //Initialize TEST pin. No interrupts on interrupts 1 and 2.
I2C_STOP(); //End communication
//This code will program the correct time into the clock. Values have to be entered in real time.
//Translation of current time into values is in on page 11 of RTC datasheet.
I2C_START(); //Start communication
I2C_WRITE(0x66); //Write to RTC2 register on the RTC. Info about this register on page page 10 & 9, RTC datasheet.
I2C_WRITE(0x48); //Hour 12
I2C_WRITE(0x00); //minute 00
I2C_WRITE(0x00); //second 00
I2C_STOP();
}//end SetTime
void Checktime(void)
{
// You Didn't Do this still...
//define RTCHour, RTCMin, RTCSec
I2C_START(); //start communication
I2C_WRITE(0x67); //access (read) register RTC 2
RTCHour=I2C_READ();
I2C_STOP(); //end communication
if((RTCHour=0x10 || RTCHour=0x90 || RTCHour=0x50 || RTCHour=0x88 || RTCHour=0x48 || RTCHour=0xC8 || RTCHour=0x28 || RTCHour=0xA8 || RTCHour=0x68 || RTCHour=0xE8 || RTCHour=0x18 || RTCHour=0x98) && GotIt != 1) // if day and no animal
NOP();
else if((RTCHour=0x10 || RTCHour=0x90 || RTCHour=0x50 || RTCHour=0x88 || RTCHour=0x48 || RTCHour=0xC8 || RTCHour=0x28 || RTCHour=0xA8 || RTCHour=0x68 || RTCHour=0xE8 || RTCHour=0x18 || RTCHour=0x98)&& GotIt == 1) // if day and animal
{
blinkLED();
}
}//end CheckTime
|
The Error Message is as follows:
Executing: "C:\Program Files (x86)\PICC\Ccsc.exe" +FH "TRTLfinalCode.c" +DF +LN +T +A +M -Z +Y=9 +EA
*** Error 128 "TRTLfinalCode.c" Line 2(25,46): A #DEVICE required before this line
1 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Fri Apr 23 19:27:50 2010
Please help, I am very lost... |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Fri Apr 23, 2010 6:47 pm |
|
|
Move #include <18F14K50.H> up to the first line. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Sage_EE
Joined: 23 Apr 2010 Posts: 5
|
Not quite |
Posted: Fri Apr 23, 2010 7:19 pm |
|
|
When I do that I get a new slew of errors that I avoided before by moving the #device line to the top of the code. I have a feeling that the PIC18F14K50 file is somehow missing from the program files but I can't figure out how to put them in there. I ran the project wizard and everything says it is supported and compatible. I am also using MPLAB and the ICD2 device to debug. |
|
|
Sage_EE
Joined: 23 Apr 2010 Posts: 5
|
ERROR |
Posted: Fri Apr 23, 2010 7:19 pm |
|
|
the error is:
Executing: "C:\Program Files (x86)\PICC\Ccsc.exe" +FH "TRTLfinalCode.c" +DF +LN +T +A +M -Z +Y=9 +EA
*** Error 18 "TRTLfinalCode.c" Line 2(26,38): File can not be opened
Not in "C:\PROGRA~2\PICC\devices\18F14K50.H"
Not in "C:\PROGRA~2\PICC\drivers\18F14K50.H"
Not in local "C:\Users\yoo\Desktop\TRTL_CODE_FINAL\18F14K50.H"
--- Info 300 "TRTLfinalCode.c" Line 3(46,52): More info: Device database: "C:\Program Files (x86)\PICC\devices4.dat"
*** Error 24 "TRTLfinalCode.c" Line 3(46,78): Unknown device type "PIC18F14K50"
*** "TRTLfinalCode.c" Line 3: Error #24: Unknown device type -- Try
*** "TRTLfinalCode.c" Line 3: Error #128: A #DEVICE required before this line
*** "TRTLfinalCode.c" Line 3: Error #128: A #DEVICE required before this line
*** "TRTLfinalCode.c" Line 3: Error #128: A #DEVICE required before this line
*** "TRTLfinalCode.c" Line 5: Error #18: File can not be opened
Not in "C:\PROGRA~2\PICC\devices\18F145K0.c"
Not in "C:\PROGRA~2\PICC\drivers\18F145K0.c"
Not in local "C:\Users\yoo\Desktop\TRTL_CODE_FINAL\18F145K0.c"
*** "TRTLfinalCode.c" Line 11: Error #111: Unknown keyword in #FUSES "MCLR"
*** "C:\PROGRA~2\PICC\drivers\math.h" Line 36: Error #128: A #DEVICE required before this line |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Fri Apr 23, 2010 7:32 pm |
|
|
The simplest way to fix the error is to add the full path with the file name to fix the error
(i.e. #include <c:\dir1\dir2\18F14K50.H> ) or change the line to
#include "18F14K50.H" and put the header file in the same directory
as the main source file. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Sage_EE
Joined: 23 Apr 2010 Posts: 5
|
Almost |
Posted: Fri Apr 23, 2010 8:25 pm |
|
|
Thanks, I found the correct compiler and associated library online at: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014&redirects=c18
Then I added the file <p18f14k50.h> to my header directory and it got rid of the original error!
Now I have a syntax error for the #device line...it seems that the commands #fuses, #use and #device are causing syntax errors... is there a library that I should be including as well?
Code: | //TRTLfinalCode.c
#include <p18f14k50.h>//Identify Microcontroller
#device *=16 adc=10 ICD=TRUE
//#include<registers.c> //include registers file
// Set up Config Bits ex. WDT,JTAG...
#fuses HS,NOWDT,NOPROTECT,NOLVP,MCLR |
any suggestions?
P.S. You've no idea how much you are helping us all out! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 23, 2010 9:37 pm |
|
|
At this point, no one knows if you are using the Microchip C18 compiler
or the CCS compiler. They are not compatible. The code written for each
compiler is not compatible with the other. Each compiler has its own
functions and extensions.
This forum is for the CCS compiler.
The C18 compiler forum is here:
http://www.microchip.com/forums/tt.aspx?forumid=3 |
|
|
Sage_EE
Joined: 23 Apr 2010 Posts: 5
|
c18 |
Posted: Fri Apr 23, 2010 10:25 pm |
|
|
While searching for a compiler that contained the library for the PIC18F14k50 I was led to use the c18 compiler in order to obtain compatible files. I am now trying to convert the CCS code that I have into c18. It appears that the majority of the code is still compatible but the commands, fuses, use, and device.
I will check out that forum and see what I can do. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|