求教PIC兄弟,帮忙解答

2020-02-09 11:40发布

为何为报无法打开文件"p18f4420.h",是不是漏掉设置什么东西?
Error[000] C:Myproj1.c 5 : Cannot open include file "p18f4420.h"
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
18条回答
suzqing618
2020-02-09 13:45
谢谢!有添加,但就是没法找到"p18f4420.h" 此文件。设置成别系列PIC,还是报同样错误,但是执行别的程序都不会,会不会是我程序有什么错误?程序如下:
//程序清单
#include <p18f4420.h>
#define CS1   PORTCbits.RC3
#define CS2   PORTCbits.RC4
#define RS    PORTCbits.RC0
#define RW    PORTCbits.RC1
#define E     PORTCbits.RC2                //上面是5条控制线的接法
#define Lcd_IO                PORTD                  //数据线接PORTD
#define SetLcd_IO        TRISD                 //由于数据线是双向传输,所以要定义控制D口的方向
#define SetLcd_CON        TRISC                //便于维护修改
#define L_lcd                KON.L
#define R_lcd                KON.R


void Delay10ms(void);
void display_led(void);
void ADRA2(void);
void initial(void);
void set_tmr1(void);
void isr_low (void);
void ioint(void);
void main(void);
unsigned int average(unsigned int average[18]);
unsigned int bit_vol[4];
unsigned int ai;

               
//const int Dis_table[20]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
//0x77,0x7c,0x39,0x4e,0x79,0x71,0x80,0x40,0x76,0x00};

// save A/D conversion result
static union AD_Res{
        unsigned int        AD_Value;
        unsigned char        AD_Tab[2];
} AD_Result;

unsigned int AD_value[18];
unsigned int AD_avr;
unsigned char num1,num2,num3,num4;
unsigned char k;

struct {
    unsigned L:1;
    unsigned R:1;
  }KON;

//bit L_lcd,R_lcd;

void initial(void)
        {
        ADCON0 = 0x09;                                 
        ADCON1 = 0X10;  //转换结果右对齐
                                                               
        TRISAbits.TRISA2=1;                
        TRISB=0X00;                //initialize the PORTD, set it to a output port
        TRISD=0X00;                //initialize the PORTD, set it to a output port
        PORTB=0xff;                //set RC0-RC3 to high level to disable the 7_seg_led

        PIE1bits.ADIE=0;                        //disable A/D interrupt
        ADCON0bits.GO=1;                        //start the A/D conversion
        INTCONbits.PEIE=1;
        PIE1bits.TMR1IE=1;
        INTCONbits.GIE=1;
        }
                                        //3,MCU执行最初总是要先设定IO口等寄存器。
void ioint(){
        ADCON0 = 0x09;                                 
        ADCON1 = 0X10;  //转换结果右对齐
        TRISAbits.TRISA2=1;

        PIE1bits.ADIE=0;                        //disable A/D interrupt
        ADCON0bits.GO=1;                        //start the A/D conversion
        INTCONbits.PEIE=1;
        PIE1bits.TMR1IE=1;
        INTCONbits.GIE=1;

PORTC=0;                                
PORTD=0;                              //先清0 C、D口,避免干扰
SetLcd_CON =0B11100000;              //把C口控制线设成输出。
SetLcd_IO=0xff;                     //D口输入。
}

void check_busy(){
CS1=1;CS2=1;
RS=0;RW=1;                                            //按照上表,设定好读取LCD状态字的控制线。
do{
  E=0;
  E=1;      
}while(Lcd_IO&0x80);                              //判断最高位状态,如果是1,则反复送E时续,直到LCD空闲

CS1=0;CS2=0;
E=0;                                            //及时拉低E,使DB口处于高阻状态,提高可靠性
if(L_lcd)
  CS1=1;
if(R_lcd)
  CS2=1;                                     //通过全局BIT变量L_LcdR_lcd传递LCD左右屏幕参数
SetLcd_IO=0;                               //使IO口处于输出状态,为向LCD写数据作准备。
}

void LCD_Write_Com(unsigned char val)   //后面当然就是向LCD写数据和指令的函数了:
{
check_busy();                        //检查LCD是否空闲
RS=0;RW=0;                          //根据上表设定控制脚,CS1、2在check_busy();里事先有设定
E=1;
Lcd_IO=val;                       //E时续下降沿输入数据
E=0;
SetLcd_IO=0xff;                 //写完数据,立即把IO口设定成高阻,提高可靠性。
}

void LCD_Write_Dat(unsigned char val)
{
check_busy();
RS=1;RW=0;
E=1;
Lcd_IO=val;
E=0;
SetLcd_IO=0xff;
}

void LCD_Clr(void)
{
unsigned char i,j;
L_lcd=1,R_lcd=1;                                    //用2个全局BIT变量传递左右屏幕,因为check_busy()函数里面有可能
                                                    //改变  CS1、CS2
LCD_Write_Com(0x3e);                            //关闭LCD显示,因为清屏幕极快,不要这句也罢。
LCD_Write_Com(0xc0);                  
for(j=8;j>0;j--){
  LCD_Write_Com(0xb8|j);               
  LCD_Write_Com(0x40);
  for(i=64;i>0;i--){
   LCD_Write_Dat(0x00);                      //对8个页面的DRAM全部送0
  }
}
LCD_Write_Com(0x3f);                     //打开LCD显示
}


void display8x8(char x,char y, const char *p){         //显示8x8的函数:x表示屏幕的 x行(0-7),y表示屏幕的y列(0-15)
char i;                                                                  
y<<=3;
L_lcd=1;R_lcd=0;
if(y&0x40){
  L_lcd=0;R_lcd=1;                                   //判断y,来选择左右屏幕
}
y&=0x3f;
LCD_Write_Com(0xb8|x);  
LCD_Write_Com(0x40|y);
for(i=8;i>0;i--){
  LCD_Write_Dat(*p++);
}
}

void display8x16(unsigned char x,unsigned char y,const char *p){   
unsigned char i;
x<<=1;
y<<=3;
L_lcd=1;R_lcd=0;
if(y&0x40){
  L_lcd=0;R_lcd=1;
}
y&=0x3f;

        LCD_Write_Com(0xb8|x);  
LCD_Write_Com(0x40|y);
for(i=8;i>0;i--){
  LCD_Write_Dat(*p++);
}
LCD_Write_Com(0xb9|x);  
LCD_Write_Com(0x40|y);
for(i=8;i>0;i--){
  LCD_Write_Dat(*p++);
}
}

void display16x16(char x,char y,const char *p){
char i;
x<<=1;
y<<=4;
L_lcd=1;R_lcd=0;
if(y&0x40){
  L_lcd=0;R_lcd=1;
}
y&=0x3f;         
LCD_Write_Com(0xb8|x);  
LCD_Write_Com(0x40|y);
for(i=16;i>0;i--){
  LCD_Write_Dat(*p++);  
}
LCD_Write_Com(0xb9|x);  
LCD_Write_Com(0x40|y);
for(i=16;i>0;i--){
  LCD_Write_Dat(*p++);
}
}

void Delay10ms(void)
{
        unsigned int i;
        for (i=100; i!=0; i--){;}       
}
               
unsigned int average(unsigned int average[18])
{
        unsigned int max=0,min=0xfff;
    unsigned long temp=0;
        unsigned char i;     
      for(i=0;i<18;i++)
                   {
                        if(max<AD_value)      
                          {max=AD_value;}
            else if(min>AD_value)
                                   {min=AD_value;}
                }
        {for (i=0;i<18;i++)
        temp+=AD_value;}
        temp=(temp-(unsigned long)max-(unsigned long)min)>>4;
      return ((int)temp);   
}                        


void set_tmr1(){
                TMR1L=0xdc;
                TMR1H=0xb;                         //*设定初值3036
                T1CON=0B10001;                 //*设定TMR1 0.125s 溢出一次*
}

void isr_low ()
{
if(PIR1bits.TMR1IF)
{
                T1CON=0B10000;         //*关闭TMR1*
                TMR1L=0xdc;
                TMR1H=0xb;                 //*TMR1 设初值*
                ADRA2();
                T1CON=0B10001;         //*从新设分频比,打开TMR1*
}
                PIR1bits.TMR1IF=0;
                return;
}

void ADRA2(void)
        {for (k=0;k<18;k++)
                {while(!PIR1bits.ADIF){;}               
                PIR1bits.ADIF=0;                                       
                AD_value[k]=(ADRESH<<8)+ADRESL;
                ADCON0bits.ADON=1;}
        }

const char a[12][8]={
{0,62,65,65,62,0,0,0},                 //0
{0,66,127,64,0,0,0,0},                //1
{0,98,81,73,70,0,0,0},
{0,34,73,73,54,0,0,0},
{0,56,38,127,32,0,0,0},
{0,79,73,73,49,0,0,0},
{0,62,73,73,50,0,0,0},
{0,3,113,9,7,0,0,0},
{0,54,73,73,54,0,0,0},
{0,38,73,73,62,0,0,0},             //9
{0,0,0,204,204,0,0,0},            //:
{0,0,0,0,0,0,0,0}                //最后全0,是为了对某个位置的数字清0
};

const char xiamen[44][8]={    //16x16点阵汉字(16列x16行)

{0x00,0x00,0xFF,0x05,0xF5,0x55,0x5D,0x55},
{0x55,0x55,0x55,0xF5,0x05,0x01,0x00,0x00},
{0x40,0x30,0x0F,0x80,0x89,0x47,0x5D,0x25},
{0x25,0x55,0x4D,0xC5,0x40,0x40,0x00,0x00},

{0x00,0x00,0xF8,0x01,0x06,0x00,0x02,0x02},
{0x02,0x02,0x02,0x02,0x02,0xFE,0x00,0x00},
{0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00},
                    
{0x10,0x10,0x88,0x88,0xC4,0xAA,0xA9,0xF9},
{0xAA,0xA4,0xC4,0x88,0x88,0x88,0x00,0x00},
{0x08,0x84,0xB6,0xD5,0x7E,0x54,0x64,0x88},
{0xB4,0xD6,0xFD,0xD6,0xA4,0x88,0x88,0x00},

{0x20,0x20,0xFF,0x20,0x20,0x04,0xF4,0x54},
{0x54,0xFF,0x54,0x55,0xF6,0x04,0x00,0x00},
{0x00,0x00,0xFF,0x00,0x04,0x04,0x0F,0x35},
{0x15,0x47,0x85,0x7F,0x07,0x04,0x04,0x00},

{0x20,0x1C,0x10,0xFF,0x90,0xB0,0x24,0x24},
{0x24,0x3F,0x24,0xE4,0x24,0x24,0x20,0x00},
{0x02,0x02,0x01,0xFF,0x00,0x00,0x01,0x05},
{0x19,0x41,0x81,0x7F,0x01,0x01,0x01,0x00},

{0x10,0x12,0x92,0x72,0xFE,0x51,0x91,0x00},
{0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00},
{0x04,0x02,0x01,0x00,0xFF,0x00,0x04,0x04},
{0x04,0x02,0x02,0x02,0xFF,0x01,0x01,0x00},

{0x08,0x08,0x88,0xFF,0x48,0x28,0x00,0xC8},
{0x48,0x48,0x7F,0x48,0xC8,0x48,0x08,0x00},
{0x01,0x41,0x80,0x7F,0x00,0x40,0x40,0x20},
{0x13,0x0C,0x0C,0x12,0x21,0x60,0x20,0x00},

{0x00,0x04,0x84,0x44,0xE4,0x34,0x2C,0x27},
{0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00},
{0x02,0x01,0x00,0x00,0xFF,0x09,0x09,0x09},
{0x29,0x49,0xC9,0x7F,0x00,0x00,0x00,0x00},

{0xFE,0x02,0x32,0x4E,0x82,0x00,0xFE,0x4A},
{0xCA,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00},
{0xFF,0x00,0x02,0x04,0x03,0x00,0xFF,0x40},
{0x20,0x03,0x0C,0x12,0x21,0x60,0x20,0x00},

{0x00,0x00,0x80,0x40,0x30,0x0E,0x84,0x00},
{0x00,0x0E,0x10,0x60,0xC0,0x80,0x80,0x00},
{0x00,0x01,0x20,0x70,0x28,0x24,0x23,0x31},
{0x10,0x10,0x14,0x78,0x30,0x01,0x00,0x00},

{0x00,0x10,0x92,0x92,0x92,0x92,0x92,0x92},
{0x92,0x92,0x12,0x02,0x02,0xFE,0x00,0x00},
{0x00,0x00,0x1F,0x04,0x04,0x04,0x04,0x04},
{0x04,0x0F,0x00,0x20,0x40,0x3F,0x00,0x00},
};


void display_lcd(void)
{        AD_avr=average(AD_value[18]);
        AD_avr=(((float)AD_avr)/1023)*5*1000;
    bit_vol[0]=(AD_avr%10);
    bit_vol[1]=(((AD_avr-num1)%100)/10);
    bit_vol[2]=(((AD_avr-num2)/100)%10);
    bit_vol[3]=(AD_avr/1000);

    ai=bit_vol[3];
    display8x8(6, 7, a[ai]);    //3行7列显示千位。
               
    ai=bit_vol[2];
    display8x8(6, 8, a[ai]);    //3行8列显示百位。

    ai=bit_vol[1];
    display8x8(6, 9, a[ai]);    //3行9列显示十位。
   
    ai=bit_vol[0];         
    display8x8(6, 10, a[ai]);   //3行10列显示个位。
}

void main(void)
{
ioint();
set_tmr1();
LCD_Clr();
        while(1)
        {
display16x16(0,0,xiamen[0]);  //
display16x16(0,1,xiamen[4]);  //
display16x16(0,2,xiamen[8]);  //
display16x16(0,3,xiamen[12]);
display16x16(0,4,xiamen[16]);
display16x16(0,5,xiamen[20]);
display16x16(0,6,xiamen[24]);
display16x16(0,7,xiamen[28]);
display16x16(1,0,xiamen[32]);
display16x16(1,1,xiamen[36]);
display16x16(1,2,xiamen[40]);
display_lcd();         
}
}

一周热门 更多>