专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
maplab C30 无法编译——delay函数
2019-03-25 18:53
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
PIC单片机
7561
5
979
用的PIC24F片子,用C30编译程序,无法编译__delay_us(ms) 函数,提示undefined reference ; 此帖出自
小平头技术问答
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
15275185009
2019-03-26 03:42
include <p24fj64ga004.h>
#define _XTAL_FREQ 8000000
#pragma config JTAGEN = 0
#pragma config LCS1 = 1
#pragma config LCS0 = 1
#pragma config FWDTEN = 0
#pragma config FNOSC2 = 0 /////01 HS
#pragma config FNOSC1 = 1
#pragma config FNOSC0 = 0
#pragma config POSCMD1 = 1
#pragma config POSCMD0 = 0
#pragma config FAMID7 = 0
#pragma config FAMID6 = 0
#pragma config FAMID5 = 0
#pragma config FAMID4 = 1
#pragma config FAMID3 = 0
#pragma config FAMID2 = 0
#pragma config FAMID1 = 0
#pragma config FAMID0 = 1
#pragma config DEV5 = 0
#pragma config DEV4 = 0
#pragma config DEV3 = 1
#pragma config DEV2 = 1
#pragma config DEV1 = 1
#pragma config DEV0 = 1
#define CS LATBbits.LATB11
#define WR LATBbits.LATB12
#define DATA LATBbits.LATB13
#define BL LATBbits.LATB10
/////////////////////
#define SCL PORTBbits.RB8
#define SDA PORTBbits.RB9
#define SDA_TRIS TRISBbits.TRISB8
#define SCL_TRIS TRISBbits.TRISB9
#define SCL2 PORTBbits.RB6
#define SDA2 PORTBbits.RB5
#define SCL2_TRIS TRISBbits.TRISB6
#define SDA2_TRIS TRISBbits.TRISB5
#define ACKBIT 0x00
#define NAKBIT 0x80
void lcd_init(void);
void lcd_write(unsigned char lcdbuf,unsigned char buflen);
void lcd_write_cmd(unsigned char cmd);
void lcd_write_data(unsigned char adr,unsigned char data);
void delay(unsigned int num);
void lcd_init(void)
{
TRISBbits.TRISB11 = 0;
TRISBbits.TRISB12 = 0;
TRISBbits.TRISB13 = 0;
TRISBbits.TRISB10 = 0;
lcd_write_cmd(0x18); //片内RC振荡器
lcd_write_cmd(0x03);// 启动LCD偏值
lcd_write_cmd(0x01); //启动系统时钟
lcd_write_cmd(0x08);//关闭声音输出
lcd_write_cmd(0x05);///关闭WDT
lcd_write_cmd(0x80);//IRQ关闭
lcd_write_cmd(0x0e);//普通模式
}
void lcd_write(unsigned char lcdbuf,unsigned char buflen)
{
unsigned char i;
for(i = 0;i < buflen;i++)
{
WR = 0;
delay(1);
if((lcdbuf & 0x80)==0x80)
{
DATA = 1;
}
else
{
DATA = 0;
}
delay(1);
WR = 1;
delay(1);
lcdbuf=lcdbuf<<1;
}
}
void lcd_write_cmd(unsigned char cmd)
{
CS = 0;
lcd_write(0x80,3);
lcd_write(cmd,9);
CS = 1;
}
void lcd_write_data(unsigned char adr,unsigned char data)
{
adr = adr<<1;
CS = 0;
lcd_write(0xa0,3);
lcd_write(adr,7);
lcd_write(data,8);
CS = 1;
}
void bstart(void)
{
SCL_TRIS = 0;
SDA_TRIS = 1;
SCL = 1;
__delay_us(10);
SDA_TRIS = 0;
SDA = 0;
__delay_us(10);
SCL = 0;
}
void bstop(void)
{
SCL_TRIS = 0;
SDA_TRIS = 0;
SDA = 0;
SCL = 1;
__delay_us(15);
SDA = 1;
__delay_us(10);
}
void bit_out(unsigned char data)
{
SCL_TRIS = 0;
SCL = 0;
__delay_us(5);
if (data & 0x80)
{
SDA_TRIS = 1;
}
else
{
SDA_TRIS = 0;
SDA = 0;
}
SCL = 1 ;
__delay_us(2);
}
void bit_in(unsigned char *data)
{
SCL_TRIS = 0;
SCL = 0;
SDA_TRIS = 1;
__delay_us(5);
SCL = 1;
__delay_us(3);
*data &= 0xFE;
if (SDA)
{
*data |= 0x01;
}
__delay_us(2);
SCL = 0;
}
unsigned char byte_out(unsigned char data)
{
unsigned char i;
unsigned char ack;
ack = 0;
for (i = 0; i < 8; i++)
{
bit_out(data);
data = data << 1;
}
bit_in(&ack);
return ack;
}
unsigned char byte_in(unsigned char ack)
{
unsigned char i;
unsigned char retval;
retval = 0;
for (i = 0; i < 8; i++)
{
retval = retval << 1;
bit_in(&retval);
}
bit_out(ack);
return retval;
}
///////////////////////I2C2
void bstart2(void)
{
SCL2_TRIS = 0;
SDA2_TRIS = 1;
SCL2 = 1;
__delay_us(10);
SDA2_TRIS = 0;
SDA2 = 0;
__delay_us(10);
SCL2 = 0;
}
void bstop2(void)
{
SCL2_TRIS = 0;
SDA2_TRIS = 0;
SDA2 = 0;
SCL2 = 1;
__delay_us(15);
SDA2 = 1;
__delay_us(10);
}
void bit_out2(unsigned char data)
{
SCL2_TRIS = 0;
SCL2 = 0;
__delay_us(5);
if (data & 0x80)
{
SDA2_TRIS = 1;
}
else
{
SDA2_TRIS = 0;
SDA2 = 0;
}
SCL2 = 1 ;
__delay_us(2);
}
void bit_in2(unsigned char *data)
{
SCL2_TRIS = 0;
SCL2 = 0;
SDA2_TRIS = 1;
__delay_us(5);
SCL2 = 1;
__delay_us(3);
*data &= 0xFE;
if (SDA2)
{
*data |= 0x01;
}
__delay_us(2);
SCL2 = 0;
}
unsigned char byte_out2(unsigned char data)
{
unsigned char i;
unsigned char ack;
ack = 0;
for (i = 0; i < 8; i++)
{
bit_out2(data);
data = data << 1;
}
bit_in2(&ack);
return ack;
}
unsigned char byte_in2(unsigned char ack)
{
unsigned char i;
unsigned char retval;
retval = 0;
for (i = 0; i < 8; i++)
{
retval = retval << 1;
bit_in2(&retval);
}
bit_out2(ack);
return retval;
}
////////////////////////////////////////////////////////////////////////////////DS1307
void write_DS1307_data(unsigned char address,unsigned char data)
{
bstart();
byte_out(0xd0);
byte_out(address);
byte_out(data);
bstop();
}
unsigned int read_DS1307_data(unsigned char address)
{
unsigned int data;
bstart();
byte_out(0xd0);
byte_out(address);
bstop();
bstart();
byte_out(0xd1);
data=byte_in(ACKBIT);
bstop();
return data;
}
///////////////////////////////////////////////////////////////////////////////EEPROM24C02
void write_24c02_data(unsigned char address,unsigned char data)
{
bstart();
byte_out(0xa0);// a1,a2,a3都接地,写地址为a0
byte_out(address);
byte_out(data);
bstop();
__delay_ms(3);
}
unsigned int read_24c02_data(unsigned char address)
{
unsigned int data;
bstart();
byte_out(0xa0);// a1,a2,a3都接地,写地址为a0
byte_out(address);
bstart();
byte_out(0xa1);
data=byte_in(NAKBIT);
bstop();
__delay_ms(3);
return data;
}
void delay(unsigned int num)
{
while(num--);
}
我现在是把各个功能挨个测试,这是i2c部分的;上面液晶显示屏的可以了。
加载中...
查看其它5个回答
一周热门
更多
>
相关问题
相关文章
一种用PIC单片机主时钟驱动的老式挂钟
0个评论
单片机程序必知的几个寄存器
0个评论
单片机 矩阵式按键
0个评论
51单片机上移植C语言的printf()
0个评论
STC89C52MCU--软件实现系统复位
0个评论
单片机C语言程序该这样写!不是教科书上教的那样!转[]
0个评论
单片机并行I/O口(P0)硬件结构
0个评论
壹:单片机的内部资源
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
#define _XTAL_FREQ 8000000
#pragma config JTAGEN = 0
#pragma config LCS1 = 1
#pragma config LCS0 = 1
#pragma config FWDTEN = 0
#pragma config FNOSC2 = 0 /////01 HS
#pragma config FNOSC1 = 1
#pragma config FNOSC0 = 0
#pragma config POSCMD1 = 1
#pragma config POSCMD0 = 0
#pragma config FAMID7 = 0
#pragma config FAMID6 = 0
#pragma config FAMID5 = 0
#pragma config FAMID4 = 1
#pragma config FAMID3 = 0
#pragma config FAMID2 = 0
#pragma config FAMID1 = 0
#pragma config FAMID0 = 1
#pragma config DEV5 = 0
#pragma config DEV4 = 0
#pragma config DEV3 = 1
#pragma config DEV2 = 1
#pragma config DEV1 = 1
#pragma config DEV0 = 1
#define CS LATBbits.LATB11
#define WR LATBbits.LATB12
#define DATA LATBbits.LATB13
#define BL LATBbits.LATB10
/////////////////////
#define SCL PORTBbits.RB8
#define SDA PORTBbits.RB9
#define SDA_TRIS TRISBbits.TRISB8
#define SCL_TRIS TRISBbits.TRISB9
#define SCL2 PORTBbits.RB6
#define SDA2 PORTBbits.RB5
#define SCL2_TRIS TRISBbits.TRISB6
#define SDA2_TRIS TRISBbits.TRISB5
#define ACKBIT 0x00
#define NAKBIT 0x80
void lcd_init(void);
void lcd_write(unsigned char lcdbuf,unsigned char buflen);
void lcd_write_cmd(unsigned char cmd);
void lcd_write_data(unsigned char adr,unsigned char data);
void delay(unsigned int num);
void lcd_init(void)
{
TRISBbits.TRISB11 = 0;
TRISBbits.TRISB12 = 0;
TRISBbits.TRISB13 = 0;
TRISBbits.TRISB10 = 0;
lcd_write_cmd(0x18); //片内RC振荡器
lcd_write_cmd(0x03);// 启动LCD偏值
lcd_write_cmd(0x01); //启动系统时钟
lcd_write_cmd(0x08);//关闭声音输出
lcd_write_cmd(0x05);///关闭WDT
lcd_write_cmd(0x80);//IRQ关闭
lcd_write_cmd(0x0e);//普通模式
}
void lcd_write(unsigned char lcdbuf,unsigned char buflen)
{
unsigned char i;
for(i = 0;i < buflen;i++)
{
WR = 0;
delay(1);
if((lcdbuf & 0x80)==0x80)
{
DATA = 1;
}
else
{
DATA = 0;
}
delay(1);
WR = 1;
delay(1);
lcdbuf=lcdbuf<<1;
}
}
void lcd_write_cmd(unsigned char cmd)
{
CS = 0;
lcd_write(0x80,3);
lcd_write(cmd,9);
CS = 1;
}
void lcd_write_data(unsigned char adr,unsigned char data)
{
adr = adr<<1;
CS = 0;
lcd_write(0xa0,3);
lcd_write(adr,7);
lcd_write(data,8);
CS = 1;
}
void bstart(void)
{
SCL_TRIS = 0;
SDA_TRIS = 1;
SCL = 1;
__delay_us(10);
SDA_TRIS = 0;
SDA = 0;
__delay_us(10);
SCL = 0;
}
void bstop(void)
{
SCL_TRIS = 0;
SDA_TRIS = 0;
SDA = 0;
SCL = 1;
__delay_us(15);
SDA = 1;
__delay_us(10);
}
void bit_out(unsigned char data)
{
SCL_TRIS = 0;
SCL = 0;
__delay_us(5);
if (data & 0x80)
{
SDA_TRIS = 1;
}
else
{
SDA_TRIS = 0;
SDA = 0;
}
SCL = 1 ;
__delay_us(2);
}
void bit_in(unsigned char *data)
{
SCL_TRIS = 0;
SCL = 0;
SDA_TRIS = 1;
__delay_us(5);
SCL = 1;
__delay_us(3);
*data &= 0xFE;
if (SDA)
{
*data |= 0x01;
}
__delay_us(2);
SCL = 0;
}
unsigned char byte_out(unsigned char data)
{
unsigned char i;
unsigned char ack;
ack = 0;
for (i = 0; i < 8; i++)
{
bit_out(data);
data = data << 1;
}
bit_in(&ack);
return ack;
}
unsigned char byte_in(unsigned char ack)
{
unsigned char i;
unsigned char retval;
retval = 0;
for (i = 0; i < 8; i++)
{
retval = retval << 1;
bit_in(&retval);
}
bit_out(ack);
return retval;
}
///////////////////////I2C2
void bstart2(void)
{
SCL2_TRIS = 0;
SDA2_TRIS = 1;
SCL2 = 1;
__delay_us(10);
SDA2_TRIS = 0;
SDA2 = 0;
__delay_us(10);
SCL2 = 0;
}
void bstop2(void)
{
SCL2_TRIS = 0;
SDA2_TRIS = 0;
SDA2 = 0;
SCL2 = 1;
__delay_us(15);
SDA2 = 1;
__delay_us(10);
}
void bit_out2(unsigned char data)
{
SCL2_TRIS = 0;
SCL2 = 0;
__delay_us(5);
if (data & 0x80)
{
SDA2_TRIS = 1;
}
else
{
SDA2_TRIS = 0;
SDA2 = 0;
}
SCL2 = 1 ;
__delay_us(2);
}
void bit_in2(unsigned char *data)
{
SCL2_TRIS = 0;
SCL2 = 0;
SDA2_TRIS = 1;
__delay_us(5);
SCL2 = 1;
__delay_us(3);
*data &= 0xFE;
if (SDA2)
{
*data |= 0x01;
}
__delay_us(2);
SCL2 = 0;
}
unsigned char byte_out2(unsigned char data)
{
unsigned char i;
unsigned char ack;
ack = 0;
for (i = 0; i < 8; i++)
{
bit_out2(data);
data = data << 1;
}
bit_in2(&ack);
return ack;
}
unsigned char byte_in2(unsigned char ack)
{
unsigned char i;
unsigned char retval;
retval = 0;
for (i = 0; i < 8; i++)
{
retval = retval << 1;
bit_in2(&retval);
}
bit_out2(ack);
return retval;
}
////////////////////////////////////////////////////////////////////////////////DS1307
void write_DS1307_data(unsigned char address,unsigned char data)
{
bstart();
byte_out(0xd0);
byte_out(address);
byte_out(data);
bstop();
}
unsigned int read_DS1307_data(unsigned char address)
{
unsigned int data;
bstart();
byte_out(0xd0);
byte_out(address);
bstop();
bstart();
byte_out(0xd1);
data=byte_in(ACKBIT);
bstop();
return data;
}
///////////////////////////////////////////////////////////////////////////////EEPROM24C02
void write_24c02_data(unsigned char address,unsigned char data)
{
bstart();
byte_out(0xa0);// a1,a2,a3都接地,写地址为a0
byte_out(address);
byte_out(data);
bstop();
__delay_ms(3);
}
unsigned int read_24c02_data(unsigned char address)
{
unsigned int data;
bstart();
byte_out(0xa0);// a1,a2,a3都接地,写地址为a0
byte_out(address);
bstart();
byte_out(0xa1);
data=byte_in(NAKBIT);
bstop();
__delay_ms(3);
return data;
}
void delay(unsigned int num)
{
while(num--);
}
我现在是把各个功能挨个测试,这是i2c部分的;上面液晶显示屏的可以了。
一周热门 更多>