专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
PIC单片机
求教PIC兄弟,帮忙解答
2020-02-09 11:40
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
4266
18
18
为何为报无法打开文件"p18f4420.h",是不是漏掉设置什么东西?
Error[000] C:Myproj1.c 5 : Cannot open include file "p18f4420.h"
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
17条回答
zhangjinxing
1楼-- · 2020-02-09 12:17
在项目设置中,添加头文件路径
加载中...
suzqing618
2楼-- · 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();
}
}
加载中...
zxq6
3楼-- · 2020-02-09 16:48
是用的c18编译器么?
加载中...
suzqing618
4楼-- · 2020-02-09 20:06
精彩回答 2 元偷偷看……
加载中...
suzqing618
5楼-- · 2020-02-10 00:40
因为初学,自己编学下面程序,用proteus仿真软件模拟,发现RA4端口没法输出(也就是说没办法选择第五个数码管),因此无法显示数字2(语句:PORTD=0xA1;),
请PIC兄弟帮忙解答,谢谢!
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
//uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
// 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void main()
{
TRISA=0x00;
TRISD=0x00;
while(1)
{
PORTA=0x20;//0011 1000 共阳极
PORTD=0xF9;
delay(1000);
PORTA=0x10;//0011 1000
PORTD=0xA1;
delay(1000);
PORTA=0x08;//0011 1000
PORTD=0xB0;
delay(1000);
PORTA=0x04;//0011 1000
PORTD=0x99;
delay(1000);
PORTA=0x02;//0011 1000
PORTD=0x92;
delay(1000);
PORTA=0x01;//0011 1000
PORTD=0x82;
delay(1000);
}
}
加载中...
suzqing618
6楼-- · 2020-02-10 03:34
打扰各位,再请教一下,
PIC16f877芯片与六位数码管搭接时,两者之间是否需要接入相关驱动器或其他元件?
若你有PIC开发板原理图,向仁兄讨一个,本人正在初学中。。。 谢谢!
我的邮箱:suzqing9527@163.com
加载中...
1
2
3
下一页
一周热门
更多
>
相关问题
PIC单片机不同的IO口驱动74HC573驱动共阴极的数码管,有的段不亮
1 个回答
一种简单精确的pic延时方法
21 个回答
谁熟悉PIC的产品发布时间的,帮看看PIC18F47K40啥版本IDE能开发
12 个回答
求AN1078对应的源代码下载地址
5 个回答
PIC单片机应用技巧
4 个回答
串口无法连续接收数据
2 个回答
求助:dsPIC33F串口通信,如何发送字符串
4 个回答
PIC45K40 IOC(interrupt-on-change)功能
2 个回答
相关文章
一种用PIC单片机主时钟驱动的老式挂钟
0个评论
×
关闭
采纳回答
向帮助了您的网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
PIC单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
关闭
您已邀请
15
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
//程序清单
#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();
}
}
请PIC兄弟帮忙解答,谢谢!
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
//uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
// 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void main()
{
TRISA=0x00;
TRISD=0x00;
while(1)
{
PORTA=0x20;//0011 1000 共阳极
PORTD=0xF9;
delay(1000);
PORTA=0x10;//0011 1000
PORTD=0xA1;
delay(1000);
PORTA=0x08;//0011 1000
PORTD=0xB0;
delay(1000);
PORTA=0x04;//0011 1000
PORTD=0x99;
delay(1000);
PORTA=0x02;//0011 1000
PORTD=0x92;
delay(1000);
PORTA=0x01;//0011 1000
PORTD=0x82;
delay(1000);
}
}
PIC16f877芯片与六位数码管搭接时,两者之间是否需要接入相关驱动器或其他元件?
若你有PIC开发板原理图,向仁兄讨一个,本人正在初学中。。。 谢谢!
我的邮箱:suzqing9527@163.com
一周热门 更多>