错误信息:
Error [285] C:\Program Files\HI-TECH Software\PICC\9.83\include\pic16f1939.h; 141.10 no identifier in declaration
Error [286] C:\Program Files\HI-TECH Software\PICC\9.83\include\pic16f1939.h; 141.10 declarator too complex
Warning [374] C:\Program Files\HI-TECH Software\PICC\9.83\include\pic16f1939.h; 141.10 missing basic type; int assumed
Error [314] C:\Program Files\HI-TECH Software\PICC\9.83\include\pic16f1939.h; 141.10 ";" expected
芯片是用的1939的,程序如下:
***************************************************
/*马达控制程序,晶振16MHZ,实现占空比调速,正反转,过流检测关断*/
***************************************************
#include<htc.h>
__CONFIG(0x09E4);
__CONFIG(0x08FF);
#define uchar unsigned char
#define uint unsigned int
#define EN1 RC4
#define EN2 RC5
#define EN3 RC6
#define threshold 3000
uchar a;//判断正反转的全局变量
uchar b;//调速时需要判断方向所引入的变量
uchar i;
int sum;
int initialspeed;
int pwmspeed;
int result;
int cc;
void init_port(void);
void init_ad(void);
void interrupt ISR(void);//使用B口电平变化中断
void pwm_forwd(int aa);
void pwm_reversl(int bb);
void ad_convert(uchar);
void delay_ms(uint);
void main()
{
a=0;
b=0;
sum=0;
initialspeed=600;//初始速度值为600即PR2的值,占空比60%
pwmspeed=0;
result=0;
init_port();
init_ad();
PORTD=0b00011100;
pwm_forwd(initialspeed);
while(1)
{
if(RB0==0)
{
delay_ms(10);
if(RB0==0)
{
while(RB0==0);
if(a==0)
{
a=1;
b=0;
PORTD=0b00011100;
if(sum==0)
{
pwm_forwd(initialspeed);
}
else
{
pwm_forwd(pwmspeed);
}
}
else
{
a=0;
b=1;
PORTD=0b11100000;
if(sum==0)
{
pwm_reversl(initialspeed);
}
else
{
pwm_reversl(pwmspeed);
}
}
}
}
if(RB1==0)
{
delay_ms(10);
if(RB1==0)
{
while(RB1==0);
sum=sum+200;
pwmspeed=initialspeed+sum;
if(pwmspeed>1000)
{
pwmspeed=1000;
}
if(b==0)
{
PORTD=0b00011100;
//pwm_forwd(pwmspeed);
}
else
{
PORTD=0b11100000;
pwm_reversl(pwmspeed);
}
}
}
if(RB2==0)
{
delay_ms(20);
if(RB2==0)
{
while(RB2==0);
sum=sum-200;
pwmspeed=initialspeed+sum;
if(pwmspeed<200)
{
pwmspeed=200;
}
if(b==0)
{
PORTD=0b00011100;
//pwm_forwd(pwmspeed);
}
else
{
PORTD=0b11100000;
pwm_reversl(pwmspeed);
}
}
}
delay_ms(10);
for(i=0;i<3;i++)
{
ad_convert(i);
if(result>threshold)
{
PORTD=0b00000000;
PORTC=0b01111111;
}
}
}
}
void init_port(void)
{
APFCON=0;//设置CCP引脚
OSCCON=0b01111010;//设置系统晶振
nWPUEN=0;//B口使能弱拉
WPUB=0b00011111;//发生电平变化中断的引脚使能弱拉
ANSELE=0;//E口被设置为IO
ANSELB=0;//B口被设置为数字IO口
TRISB=0b00001111;
IOCBP=0b00001000;//RB3设置成上下沿都可中断
IOCBN=0b00001000;//
INTCON=0b10001000;//只有一个引脚为电平变化中断
IOCBF=0b00000000;//电平变化中断寄存器清零
TRISC=0;
TRISD=0;
TRISE=0;
PORTC=0b01111111;
PORTE=0;
}
void init_ad(void)
{
TRISA0=1;
TRISA1=1;
TRISA2=1;
ANSELA=0b00111000;
ADCON1=0b11010000;//设置AD转换的频率为Fosc/16,Tad=1微秒
ADIF=0;
ADIE=1;
GIE=1;
PEIE=1;
}
void ad_convert(uchar chan)
{
ADCON0=(chan<<2);
ADON=1;
delay_ms(10);
ADGO=1;
while(ADGO);
result=ADRESH<<8;
result|=ADRESL;
}
void interrupt ISR(void)
{
if((IOCIF&IOCBF3)==1)
{
delay_ms(10);
if(RB3==0)
{
if(sum==0)
{
pwm_forwd(initialspeed);
}
else
{
pwm_forwd(pwmspeed);
}
}
else
{
if(sum==0)
{
pwm_reversl(initialspeed);
}
else
{
pwm_reversl(pwmspeed);
}
}
IOCIF=0;
IOCBF3=0;
}
}
void pwm_forwd(int aa)
{
TRISC1=1;
TRISC2=1;
TRISE0=1;
PR2=249;
CCP1CON=0b00001100;
CCP2CON=0b00001100;
CCP3CON=0b00001100;
CCPR1L=(aa>>2);
CCPR2L=(aa>>2);
CCPR3L=(aa>>2);
CCPTMRS0=0b11000000;
CCPTMRS1=0b00000011;
TMR2IF=0;
T2CON=0b00000110;
TRISC1=0;
TRISC2=0;
TRISE0=0;
RC0=0;
RC3=0;
RE1=0;
}
void pwm_reversl(int bb)
{
bb=1000-bb;
TRISC1=1;
TRISC2=1;
TRISE0=1;
PR2=249;
CCP1CON=0b00001100;
CCP2CON=0b00001100;
CCP3CON=0b00001100;
CCPR1L=bb>>2;
CCPR2L=bb>>2;
CCPR3L=bb>>2;
CCPTMRS0=0b11000000;
CCPTMRS1=0b00000011;
TMR2IF=0;
T2CON=0b00000110;
TRISC1=0;
TRISC2=0;
TRISE0=0;
RC0=1;
RC3=1;
RE1=1;
}
void delay_ms(uint x)
{
uint a,b;
for(a=0;a<x;a++)
for(b=398;b>0;b--)
NOP();
}
|