|
|
View previous topic :: View next topic |
Author |
Message |
faridh3
Joined: 17 Mar 2014 Posts: 21
|
100 errors problem !! |
Posted: Mon Mar 17, 2014 8:03 am |
|
|
Hello,
After building my project, the code gave me 100 errors all the same and i don't know how to fix it.
The errors are:
Expecting a declaration
Expecting a (
Expecting an identifier
Thanks.
This is my code:
Code: |
#include "demo.c"
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
void lcd_init() {
BYTE i;
set_tris_lcd(LCD_WRITE);
lcd.rs = 0;
lcd.rw = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
lcd_setCG();
lcd_send_byte(0,0x80);
}
void main() {
set_tris_a(0x);
set_tris_b(0x55);
set_tris_c(0x55);
lcd_init();
int i=1;
int level;
do
{
int counterR=6;
int counterL=5;
level=input_state(PIN_A0);
if(level==0)
output_low(PIN_A1);
else{
output_high(PIN_A1);
counterL=counterL-1;
}
level=input_state(PIN_A2);
if(level==0)
output_low(PIN_A3);
else{
output_high(PIN_A3);
counterL=counterL-1;
}
level=input_state(PIN_A4);
if(level==0)
output_low(PIN_A5);
else{
output_high(PIN_A5);
counterL=counterL-1;
}
level=input_state(PIN_B0);
if(level==0)
output_low(PIN_B1);
else{
output_high(PIN_B1);
counterL=counterL-1;
}
level=input_state(PIN_B2);
if(level==0)
output_low(PIN_B3);
else{
output_high(PIN_B3);
counterL=counterL-1;
}
level=input_state(PIN_B4);
if(level==0)
output_low(PIN_B5);
else{
output_high(PIN_B5);
counterR=counterR-1;
}
level=input_state(PIN_B6);
if(level==0)
output_low(PIN_B7);
else{
output_high(PIN_B7);
counterR=counterR-1;
}
level=input_state(PIN_C0);
if(level==0)
output_low(PIN_C1);
else{
output_high(PIN_C1);
counterR=counterR-1;
}
level=input_state(PIN_C2);
if(level==0)
output_low(PIN_C3);
else{
output_high(PIN_C3);
counterR=counterR-1;
}
level=input_state(PIN_C4);
if(level==0)
output_low(PIN_C5);
else{
output_high(PIN_C5);
counterR=counterR-1;
}
level=input_state(PIN_C6);
if(level==0)
output_low(PIN_C7);
else{
output_high(PIN_C7);
counterR=counterR-1;
}
}
while(i=1);
} |
|
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon Mar 17, 2014 8:33 am |
|
|
Code: | if(level==0)
output_low(PIN_A1);
else{
output_high(PIN_A1);
counterL=counterL-1;
} |
I know this gives errors in 5.019 you should include {} on the output_low as well
Code: | if(level==0)
{ output_low(PIN_A1); }
else{
output_high(PIN_A1);
counterL=counterL-1;
} |
|
|
|
faridh3
Joined: 17 Mar 2014 Posts: 21
|
|
Posted: Mon Mar 17, 2014 8:37 am |
|
|
i already tried to do so and it did not solve my problem
thank you alan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 17, 2014 9:11 am |
|
|
Quote: | void lcd_init() {
BYTE i;
set_tris_lcd(LCD_WRITE);
lcd.rs = 0;
lcd.rw = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
lcd_setCG();
lcd_send_byte(0,0x80);
} |
What is this LCD driver ? Why are you including the init routine from
the LCD driver in your program as a separate routine ? Where's the
#include near the start of your program for this lcd driver ? It's missing.
What's in this file ? Post it. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Mon Mar 17, 2014 9:20 am |
|
|
The first thing is demo.c.
Generally, the _only_ include that should be done before the fuses and clock, is the actual processor definition. Anything that requires serial I/O, timings etc. etc., is dependant on having the timings, RS232 etc., defined first. Since demo.c, must include an LCD function (which will use timings), this is not the way to get it working....
Then CCS has a 'traditional' problem, that certain types of error, will only get reported, when the compiler can't cope any more. When this happens you then get dozens of errors on the next few lines. This is commonly caused by something like an imbalanced bracket dozens or hundreds of lines before - I suggest in demo.c.
Move demo.c to after the fuse/clock definitions, and use the tool to match braces (or an editor with this ability of you don't have the IDE), and check that these are all balanced in demo.c.
Why waste a memory location to store 'i'?. while (TRUE) works just as well (and better since you keep assigning one to i, rather than just testing it)...
Code: |
if(level==0)
output_low(PIN_A1);
else{
output_high(PIN_A1);
counterL=counterL-1;
}
|
"I know this gives errors in 5.019 you should include {} on the output_low as well".
Er. no. Not needed, and does not give errors in 5.019 (or any other CCS compiler). I'd suggest if it is giving errors for you, the instruction you are using in the single line, is not a function, but a #defined macro. This is one reason why #defines should always be in capitals. So:
Code: |
if(level==0)
output_low(PIN_A1);
else
{
output_high(PIN_A1);
counterL=counterL-1;
}
//perfectly legal and does not give errors, but:
#define silly_thing(x) output_low(x);delay_us(1)
if(level==0)
silly_thing(PIN_A1);
else
{
output_high(PIN_A1);
counterL=counterL-1;
}
//will now give an error
|
Best Wishes |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon Mar 17, 2014 9:45 am |
|
|
You're right. Just had a look and it is a macro |
|
|
faridh3
Joined: 17 Mar 2014 Posts: 21
|
|
Posted: Mon Mar 17, 2014 11:15 am |
|
|
Thanks a lot guys,
in case of any other problem, i'll let you know.
demo.c:
Code: | #include "demo.h"
#include "LCD2x16.h"
///////////////////////////////////////////////////////////////////////////////
BOOLEAN Ext_Int_detect = FALSE;
#int_EXT //interrupt service routine for INT0
void EXT_isr(void)
{
Ext_Int_detect = TRUE;
}
///////////////////////////////////////////////////////////////////////////////
unsigned int16 old_CCP1=0, CCP1_diff;
#int_CCP1 //interrupt service routine for Capture 1
void CCP1_isr(void)
{
CCP1_diff = CCP_1 - old_CCP1;
old_CCP1 = CCP_1; //prepare for next capture
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void main()
{
int8 counter=0; //same as: byte counter;
int8 ADC_val;
float freq;
//setup ADC
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_12);
set_adc_channel(0); //select channel
setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1 ); //prepare timer1 for CCP1
setup_ccp1(CCP_CAPTURE_FE); //set up input capture for frequency detect
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(INT_CCP1); //enable interrupt for input capture
enable_interrupts(GLOBAL);
set_tris_c(0xBF);
delay_ms(500); //wait a bit
lcd_init(); //initialize 16x2 LCD
printf(lcd_putc, "Hello World- LCD!\nMicro Demo"); // print on LCD
printf("\fHello World- UART\n\r"); //print over UART (terminal)
delay_ms(1000); //wait 1 sec
lcd_putc('\f'); //clear LCD
while(TRUE)
{
if (Ext_Int_detect == TRUE)
{
printf("\n\rINT0 detected");
Ext_Int_detect = FALSE;
}
if (!input(PIN_B1))
{
delay_ms(20); //debounce delay
printf("\n\rPB3 pressed!");
while (!input(PIN_B1));
delay_ms(20); //debounce delay
printf("\n\rPB3 released!");
counter++;
lcd_gotoxy(1,1);
printf(lcd_putc, "C: %03u", counter);
}
ADC_val = read_adc();
lcd_gotoxy(1,2);
printf(lcd_putc, "ADC val: %03u", ADC_val);
//display frequency:
freq = 1/((float)CCP1_diff/1000000);
lcd_gotoxy(8,1);
printf(lcd_putc, "F=%.2f", freq);
delay_ms(100); //main loop delay (optional)
}
} |
demo.h:
Code: |
#include <18F4520.h>
#device adc=8 //ADC in 8-bit mode
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
|
LCD2x16:
Code: | #ifndef LCD2x16
#define LCD2x16
struct lcd_pin_map {
int data : 4;
BOOLEAN unused;
BOOLEAN enable;
BOOLEAN rw;
BOOLEAN rs;
} lcd;
#byte lcd = 0xF83 // This puts the entire structure
#define set_tris_lcd(x) set_tris_d(x)
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the second line
BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
// These bytes need to be sent to the LCD
// to start it up.
// The following are used for setting
// the I/O port direction register.
struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode
struct lcd_pin_map const LCD_READ = {15,0,0,0,0}; // For read mode
BYTE lcd_read_byte() {
BYTE low,high;
set_tris_lcd(LCD_READ);
lcd.rw = 1;
delay_cycles(1);
lcd.enable = 1;
delay_cycles(1);
high = lcd.data;
lcd.enable = 0;
delay_cycles(1);
lcd.enable = 1;
delay_us(1);
low = lcd.data;
lcd.enable = 0;
set_tris_lcd(LCD_WRITE);
return( (high<<4) | low);
}
void lcd_send_nibble( BYTE n ) {
lcd.data = n;
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}
void lcd_send_byte( BYTE address, BYTE n ) {
lcd.rs = 0;
while ( bit_test(lcd_read_byte(),7) ) ;
lcd.rs = address;
delay_cycles(1);
lcd.rw = 0;
delay_cycles(1);
lcd.enable = 0;
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
void lcd_setCG()
{
lcd_send_byte(0,0x40);
lcd_send_byte(1,0x06);
lcd_send_byte(1,0x09);
lcd_send_byte(1,0x09);
lcd_send_byte(1,0x06);
lcd_send_byte(1,0x00);
lcd_send_byte(1,0x00);
lcd_send_byte(1,0x00);
lcd_send_byte(1,0x00);
}
void lcd_init() {
BYTE i;
set_tris_lcd(LCD_WRITE);
lcd.rs = 0;
lcd.rw = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
lcd_setCG();
lcd_send_byte(0,0x80);
}
void lcd_gotoxy( BYTE x, BYTE y) {
BYTE address;
if(y!=1)
address=lcd_line_two;
else
address=0;
address+=x-1;
lcd_send_byte(0,0x80|address);
}
void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2); break;
case '\b' : lcd_send_byte(0,0x10); break;
default : lcd_send_byte(1,c); break;
}
}
char lcd_getc( BYTE x, BYTE y) {
char value;
lcd_gotoxy(x,y);
while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}
#endif |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Mon Mar 17, 2014 11:22 am |
|
|
You have two sets of fuses, two main's etc.. Never going to work. Read the manual, look at the examples, realise that you can only have one program, and start again. |
|
|
faridh3
Joined: 17 Mar 2014 Posts: 21
|
|
Posted: Mon Mar 17, 2014 2:51 pm |
|
|
Thanks a lot |
|
|
|
|
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
|