|
|
View previous topic :: View next topic |
Author |
Message |
yalisoylu
Joined: 28 Aug 2015 Posts: 1
|
CCS C compiler expecting an identifier |
Posted: Fri Aug 28, 2015 4:05 am |
|
|
Hello,
In 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 ---error 43
Expecting a ( ---error 48
Expecting an identifier ---error 28
Illegal C character in input file 0x40 ---error 1
Thanks.
This is my code: Code: |
#include <main.h>
#include <htc.h>
#include "delay.h"
#include <math.h>
__CONFIG (1,HS);
__CONFIG (2,PWRTDIS & WDTDIS & BORDIS);
__CONFIG (3,CCP2RB3);
__CONFIG (4,DEBUGEN & LVPDIS & STVRDIS);
__CONFIG (5,CP0_OFF);
__CONFIG (6,WRTEN);
__CONFIG (7,TRU);
//
#define _XTAL_FREQ 20000000
#define databits PORTD
#define debounce 150
#define CCP1Y DC1B0
#define CCP1X DC1B1
#define avg 15
#define poweradjustmentinterval 15
#define dutycounterval 150
#define frqcounterval 100
#define defaultpwr 9000
static bit BL @((unsigned)&PORTA*8+5);//PORTA,5
static bit RS @((unsigned)&PORTE*8+1);//PORTE,1
static bit EN @((unsigned)&PORTE*8+0);//PORTE,0
static bit LED @((unsigned)&PORTE*8+2);//PORTE,2
static bit UP @((unsigned)&PORTC*8+0);//
static bit DOWN @((unsigned)&PORTC*8+1);//
static bit OK @((unsigned)&PORTB*8+0);//
static bit INC @((unsigned)&PORTC*8+3);//
static bit DEC @((unsigned)&PORTC*8+4);//
static bit TESTSIGNAL @((unsigned)&PORTB*8+4);//
char counter = 0, crsr=1,module=1,duty=12,strr[4], k=0, ii, dutycounter = dutycounterval, _manduty=1, maxpr2;
int frq, pwr_adj=0, okpressed=1;
int ledtimer=0; exitcommand=400;
int temp1;
int powerX[avg*5],powerY[avg*5];
float currentpower;
unsigned int currentpowerX,currentpowerX1;
int pwr, actpwr, prevfrqpwr=0, frqcounter=frqcounterval;
int prevpwr=0;
bit frq_search;
bit sweep=0;
bit _measurepower=0;
bit _commandmode=0;
bit _changevalue=0;
bit _screen = 0;
bit _screenadj=0;
bit _pwr_adj=0,_pwradjustable=0;
void screen(void);
void updatePWM(void);
void interrupt tmrr(void){
if (T0IF)//Timer0 Kesme bayrağı kontrol ediliyor.
{
counter++;
//if (counter==10){
_measurepower=1;
// counter=0;
//}
if(!OK || !UP || !DOWN || !INC || !DEC){
ledtimer=3000;
}
if (ledtimer>0){
BL=1;
ledtimer--;
}
if (ledtimer <=0){
BL=0;
}
if(!OK && _commandmode)
if (!exitcommand--){
_commandmode=0;
_changevalue=0;
_screen=1;
okpressed=1;
_pwradjustable=0;
exitcommand=400;
}
if(!OK && !_commandmode){
okpressed++;
if (okpressed>1990)
okpressed=1989;
if(okpressed==400){
_commandmode=1;
_screenadj=1;
}
}
else if(OK)
if(_commandmode==1)
okpressed--;
else
okpressed=1;
if (!okpressed){
_commandmode=0;
_changevalue=0;
_screen=1;
okpressed=1;
_pwradjustable=0;
exitcommand=400;
}
}
TMR0=60;//Timer0 registerına 10 ms'de bir kesme oluşturacak değer yükleniyor.
T0IF=0;// Kesme bayrağı sıfırlanıyor.
}
//*****************************************************************************
//*****************************************************************************
void init()
{
_screen = 1;
TRISE = 0x00;
TRISD = 0x00;
TRISC = 0xFB;
TRISA = 0xFF;
TRISB = 0xEF;
T0CS=0;// Clock palsi kaynağı olarak dahili osilatör seçildi.
T0SE=0;
PSA=0;//Prescaler değeri Timer0 için kullanılacak.
T0PS2=1;//Prescaler değeri 1:32 olarak seçildi.
T0PS1=1;
T0PS0=1;
GIE=1;// tüm kesmelere izin verdik.
T0IF=0;//Kesme bayrağını her ihtimale karşı sıfırladık
TMR0=60 ;//Timer0 registerına 10 ms'de bir kesme oluşturacak değer yükleniyor.
T0IE=1;//Timer0 kesmesini aktif ettik.
//PWM settings
T2CKPS1 = 0;
T2CKPS0 = 0;
CCP1M0 = 1;
CCP1M1 = 1;
CCP1M2 = 1;
CCP1M3 = 1;
TMR2ON = 0;
PR2 = 155;//25KHz-199 24KHz-207 32khz-155 35KHz-143
updatePWM();
TMR2ON = 1;
}
//*****************************************************************************
void num2str(int c) {
char i=0,j;
int dum1;
strr[0]=0x30;strr[1]=0x30;strr[2]=0x30;strr[3]=0x30;
while (c>0){
dum1=(int)(c/10);
strr[3-i] =(c-dum1*10)+0x30;
c=dum1;
i++;
}
}
// LCD ROUTINES//
void LCD_STROBE(void){
EN=1;
DelayUs(1);
EN=0;
}
void DATA(unsigned char c){
RS=1;
DelayUs(50);
databits = c>>4;
LCD_STROBE();
databits = c;
LCD_STROBE();
}
void CMD1(unsigned char c){
RS=0;
DelayUs(50);
databits = c>>4;
LCD_STROBE();
}
void CMD(unsigned char c){
RS=0;
DelayUs(50);
databits = c>>4;
LCD_STROBE();
databits = c;
LCD_STROBE();
}
void CLR(void){
CMD(0x01);
DelayMs(3);
}
void LCD_INIT(void){
DelayMs(20);
CMD1(0x38);
DelayMs(6);
CMD1(0x38);
DelayUs(120);
CMD1(0x38);
CMD1(0x28);
CMD(0x28);
CMD(0x0C);
CLR();
CMD(0x06);
}
void string1 (char *q){
while (*q){
DATA(*q++);
}
}
////////////////////////////////////////////////
void screen(){
Delay Ms(300);
CLR();
CMD(0x80);
string1("FREQUENCY:");
num2str(frq);
DATA(strr[1]);
DATA(strr[2]);
DATA(0x2C);
DATA(strr[3]);
string1(" KHz");
CMD(0xC0);
string1("FRQ SEARCH:");
if (frq_search)
string1("ENABLE");
else
string1("DISABLE");
CMD(0x94);
string1("SWEEP:");
if (sweep)
string1("ON");
else
string1("OFF");
CMD (0x9D);
string1("/DTY:%");
num2str(duty);
DATA(strr[2]);
DATA(strr[3]);
CMD(0xD4);
string1("POWER:");
num2str(pwr);
DATA(strr[0]);
DATA(strr[1]);
DATA(strr[2]);
DATA(strr[3]);
if (_pwr_adj){
string1("/REQ.:");
num2str(pwr_adj);
DATA(strr[0]);
DATA(strr[1]);
DATA(strr[2]);
DATA(strr[3]);
}
else {
string1("/DEF.:");
num2str(defaultpwr);
DATA(strr[0]);
DATA(strr[1]);
DATA(strr[2]);
DATA(strr[3]);
}
}
void screenadj(){
CLR();
CMD(0x80);
DATA(0x20);
CMD(0xC0);
DATA(0x20);
CMD(0x94);
DATA(0x20);
CMD(0xD4);
DATA(0x20);
CMD(0xDE);
DATA(0x20);
if (crsr==1)
CMD(0x80);
else if (crsr==2)
CMD(0xC0);
else if (crsr==3)
CMD(0x94);
else if (crsr==4)
CMD(0xD4);
else if (crsr==5)
CMD(0xDE);
if (_commandmode && !_changevalue)
string1(">");
else if (_changevalue)
DATA(0x3D);
CMD(0x81);
string1("SWEEP:");
if (sweep)
string1("ON ");
else
string1("OFF");
CMD(0xC1);
string1("FRQ SEARCH:");
if (frq_search){
string1("ON ");
CMD(0xD5);
string1("FRQ:AUTO");
}
else{
string1("OFF");
CMD(0xD5);
string1("FRQ:");
num2str(frq);
DATA(strr[1]);
DATA(strr[2]);
DATA(0x2C);
DATA(strr[3]);
}
CMD(0x95);
string1("POWER:");
if (!_pwr_adj)
string1("AUTO");
else{
string1("MAN:");
num2str(pwr_adj);
DATA(strr[0]);
DATA(strr[1]);
DATA(strr[2]);
DATA(strr[3]);
}
CMD(0xDF);
string1("DTY:%");
num2str(duty);
DATA(strr[2]);
DATA(strr[3]);
}
void inc_crsr(){
switch(crsr){
case 1:
sweep=1;
break;
case 2:
frq_search=1;
break;
case 3:
if(_pwradjustable){
pwr_adj+= 10;
_manduty=0;
if (pwr_adj>2000)
pwr_adj=2000;
}
if (!_pwr_adj && !_pwradjustable){
_pwr_adj=1;
_pwradjustable=1;
}
break;
case 4:
PR2--;
if (PR2<61)
PR2=61;
updatePWM();
break;
case 5:
_manduty=1;
duty++;
updatePWM();
break;
}
_screenadj=1;
}
void dec_crsr(){
switch(crsr){
case 1:
sweep=0;
break;
case 2:
frq_search=0;
break;
case 3:
if(_pwradjustable){
pwr_adj-= 10;
if (pwr_adj>65000)
pwr_adj=0;
if (pwr_adj==0){
_pwr_adj=0;
_pwradjustable=0;
}
_manduty=0;
}
if (_pwr_adj && !_pwradjustable){
_pwr_adj=0;
}
break;
case 4:
PR2++;
if (PR2>254)
PR2=254;
updatePWM();
break;
case 5:
_manduty=1;
duty--;
updatePWM();
break;
}
_screenadj=1;
}
void readadc(){
ADCON1=0x82;
int i;
ADCON0=0x01;
DelayMs(1);
ADIF=0;
GO_nDONE=1;
while(GO_nDONE)
continue;
temp1=(ADRESL+(unsigned int)ADRESH*256);
// powerX[k]=(int)(temp1/100);
// powerY[k]=(int)(temp1%100);
// k=k+1;
// if (k==avg*5)
// k=0;
// currentpower=0.0;
// for(ii=0;ii<avg;ii++){
// currentpowerX = 0;
// for (i=0;i<5;i++){
// temp1=(int)(100*powerX[i+ii*5]*powerX[i+ii*5] + 2*powerX[i+ii*5]*powerY[i+ii*5] +(int)(powerY[i+ii*5]*powerY[i+ii*5]/100));
// currentpowerX +=temp1;
// }
//
// currentpower += ((float)currentpowerX/100.0);
// }
currentpower=temp1;//sqrt(currentpower/(5*avg))*100;
ADCON0=0x00;
}
void main(void) {
TESTSIGNAL=0;
init();
DelayMs(250);
LCD_INIT();
DelayMs(200);
frq_search=0;
while(1){
if(frq_search){
_manduty=1;
if(!frqcounter--){
if(actpwr>prevfrqpwr){
maxpr2=PR2;
prevfrqpwr=actpwr;
}
PR2--;
frqcounter=frqcounterval;
updatePWM();
CMD(0x8A);
num2str(frq);
DATA(strr[1]);
DATA(strr[2]);
DATA(0x2C);
DATA(strr[3]);
}
if(PR2==172){//172-29KHz 125-40Kz
frq_search=0;
PR2=maxpr2;
prevfrqpwr=0;
updatePWM();
CMD(0x8A);
num2str(frq);
DATA(strr[1]);
DATA(strr[2]);
DATA(0x2C);
DATA(strr[3]);
_manduty=0;
}
}
if (1){//_measurepower
readadc();
TESTSIGNAL = !TESTSIGNAL;
pwr=(int)(-195.+161.3*(currentpower*(5.0/(1024.0))));
// if (pwr<217){
// pwr=pwr*1.14;
// }
// else if (pwr<725) {
// pwr=pwr*0.37+167;
// }
// else if (pwr<1140){
// pwr=pwr*0.70-72;
// }
// else if (pwr<12894){
// pwr=pwr*0.70-72;
// }
//pwr=pwr*0.22;
// actpwr=pwr;
// if (prevpwr-pwr>5){
// prevpwr=pwr;
// }
// else if (pwr-prevpwr>5){
// prevpwr=pwr;
// }
// else{
// pwr=prevpwr;
// }
if (!_commandmode){
CMD(0xDA);
num2str(pwr);
DATA(strr[0]);
DATA(strr[1]);
DATA(strr[2]);
DATA(strr[3]);
}
if (!_manduty)
if (_pwr_adj){
if (pwr<pwr_adj-poweradjustmentinterval){
if (!dutycounter--){
duty++;
updatePWM();
dutycounter=dutycounterval;
}
}
else if (pwr>pwr_adj+poweradjustmentinterval){
if (!dutycounter--){
duty--;
updatePWM();
dutycounter=dutycounterval;
}
}
_measurepower=0;
}
else {
if (pwr<defaultpwr-poweradjustmentinterval){
if (!dutycounter--){
duty++;
updatePWM();
dutycounter=dutycounterval;
}
}
else if (pwr>defaultpwr+poweradjustmentinterval){
if (!dutycounter--){
duty--;
updatePWM();
dutycounter=dutycounterval;
}
}
}
}
if(_screen){
screen();
_screen=0;
}
if(_screenadj){
screenadj();
_screenadj=0;
}
if(_commandmode && (okpressed<1990))
if(!_changevalue){
if(!UP)
DelayMs(debounce);
if(!UP){
crsr=crsr-1;
okpressed=1989;
_screenadj=1;
}
if(crsr==0)
crsr=5;
if(!DOWN)
DelayMs(debounce);
if(!DOWN){
crsr=crsr+1;
okpressed=1989;
_screenadj=1;
}
if(crsr==6)
crsr=1;
if(!OK){
DelayMs(debounce);
if(!OK){
okpressed=2000;
if(1){
_screenadj=1;
_changevalue=1;
}
}
}
}
else
{
if(!UP)
DelayMs(debounce);
if(!UP)
{
inc_crsr();
okpressed=1989;
}
if(!DOWN)
DelayMs(debounce);
if(!DOWN)
{
dec_crsr();
okpressed=1989;
}
if(!OK){
DelayMs(debounce);
if(!OK){
//DelayMs(200);
if(1){
_changevalue=0;
okpressed=1989;
_screenadj=1;
_commandmode=1;
}
}
}
}
}
}
void updatePWM()
{
unsigned int temp;
float freq;
if (duty>250)
duty=0;
else if (duty>40)
duty=40;
CMD(0xA3);
num2str(duty);
DATA(strr[2]);
DATA(strr[3]);
frq = (int)(10.0*(((float)(_XTAL_FREQ)/4000.0) / (PR2+1))+0.5);
freq = (float)(frq/10);
temp=((duty*(1/(freq))/100)*(_XTAL_FREQ/1000));
CCP1X = 0;
if(temp%2)
CCP1X = 1;
temp=(int)(temp/2);
CCP1Y = 0;
if(temp%2)
CCP1Y = 1;
CCPR1L = 0;
temp=(int)(temp/2);
if(temp%2)
CCPR1L = CCPR1L + 0b00000001;
temp=(int)(temp/2);
if(temp%2)
CCPR1L = CCPR1L + 0b00000010;
temp=(int)(temp/2);
if(temp%2)
CCPR1L = CCPR1L + 0b00000100;
temp=(int)(temp/2);
if(temp%2)
CCPR1L = CCPR1L + 0b00001000;
temp=(int)(temp/2);
if(temp%2)
CCPR1L = CCPR1L + 0b00010000;
temp=(int)(temp/2);
if(temp%2)
CCPR1L = CCPR1L + 0b00100000;
temp=(int)(temp/2);
if(temp%2)
CCPR1L = CCPR1L + 0b01000000;
temp=(int)(temp/2);
if(temp%2)
CCPR1L = CCPR1L + 0b10000000;
}]
|
_________________ CHE SARA SARA... |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Aug 28, 2015 12:46 pm |
|
|
this is a CCS forum. The error you see is the tip of an iceberg of trouble.
be sure to come back when you have some CCS code to discuss.
what you posted is technically speaking , An obviously COPIED
from lala-land, mega-MESS of NON-CCS code.
#include <htc.h>
things like:
Code: |
int ledtimer;
// and later ...
ledtimer=3000;
|
of course , silly stuff like __CONFIG()
all pure JUNK to CCS ....
it won't compile - it's garbage.
try reading this:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf |
|
|
|
|
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
|