#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit CS88 = P2^2; //8X8点阵使能
sbit DS1302=P2^7; //HJ-C52主板 时钟复位 关掉DS1302 以免影响其他IO口实验。
sbit LCD1602=P2^5;//HJ-C52主板 LCD1602复位 关掉LCD1602显示 以免影响其他IO口实验。
void delay1();
//Motor
sbit F1 = P1^0;
sbit F2 = P1^1;
sbit F3 = P1^2;
sbit F4 = P1^3;
unsigned char code FFW[8]={0xfe,0xfc,0xfd,0xf9,0xfb,0xf3,0xf7,0xf6}; //反转
unsigned char code FFZ[8]={0xf6,0xf7,0xf3,0xfb,0xf9,0xfd,0xfc,0xfe}; //正转
unsigned int K, rate;
sbit dula=P2^6;
sbit wela=P2^7;
sbit LCD_RS = P1^0;
sbit LCD_RW = P1^1;
sbit LCD_EN = P2^5;
int time;
int succeed_flag;
uchar timeL;
uchar timeH;
uchar distance;
uchar H;
sbit Trig=P2^4;
sbit Echo=P3^2;
uchar code dis1[] = {"The juli is: "};
uchar dis2[] = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
/**********************************************************
步进电机驱动 *
***********************************************************/
void motor_ffw(void)
{
unsigned char i;
for (i=0; i<8; i++) //一个周期转30度
{
P1 = FFW[i]&0x1f; //取数据
delay1(); //调节转速
}
}
/********************************************
延时程序
*********************************************/
void delay1(void)
{
unsigned int k,t;
t=rate;
while(t--)
{
for(k=0; k<150; k++)
{ }
}
}
/********************************************************
*********************************************************/
void motor_turn(void)
{
unsigned char x;
rate=0x0a;
x=0x40;
do
{
motor_ffw(); //加速
rate--;
}while(rate!=0x01);
do
{
motor_ffw(); //匀速
x--;
}while(x!=0x01);
do
{
motor_ffw(); //减速
rate++;
}while(rate!=0x0a);
}
void delay2(int ms)
{
int i;
while(ms--)
{
for(i = 0; i< 110; i++)
{
nop();
}
}
}
void delay2_20us()
{
uchar a ;
for(a=0;a<100;a++);
}
bit lcd_busy()
{
bit result;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
nop();
nop();
nop();
nop();
result = (bit)(P0&0x80);
LCD_EN = 0;
return result;
}
void lcd_wcmd(uchar cmd)
{
while(lcd_busy());
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
nop();
nop();
P0 = cmd;
nop();
nop();
LCD_EN = 1;
nop();
nop();
LCD_EN = 0;
}
void lcd_wdat(uchar dat)
{
while(lcd_busy());
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
P0 = dat;
nop();
nop();
LCD_EN = 1;
nop();
nop();
LCD_EN = 0;
}
void lcd_pos(uchar pos)
{
lcd_wcmd(pos|0x80); //数据指针=80+地址变量
}
void lcd_init()
{
dula=0;
wela=0;
lcd_wcmd(0x38); //16*2显示,5*7点阵,8位数据
delay2(5);
lcd_wcmd(0x38);
delay2(5);
lcd_wcmd(0x38);
delay2(5);
lcd_wcmd(0x0c); //显示开,关光标
delay2(5);
lcd_wcmd(0x06); //移动光标
delay2(5);
lcd_wcmd(0x01); //清除LCD的显示内容
delay2(5);
}
main()
{
uchar i,a,b,c;
delay2(10);
lcd_init(); // 初始化LCD
Trig=0; //首先拉低脉冲输入引脚
EA=1; //打开总中断0
TMOD=0x10; //定时器1,16位工作方式
while(1)
{
EA=0; //关总中断
Trig=1; //超声波输入端
delay2_20us(); //延时20us
Trig=0; //产生一个20us的脉冲
while(Echo==0); //等待Echo回波引脚变高电平
succeed_flag=0; //清测量成功标志
EA=1;
EX0=1; //打开外部中断0
TH1=0; //定时器1清零
TL1=0; //定时器1清零
TF1=0; //计数溢出标志
TR1=1; //启动定时器1
delay2(20); //等待测量的结果
TR1=0; //关闭定时器1
EX0=0; //关闭外部中断0
if(succeed_flag==1)
{
time=timeH*256+timeL;
distance=time*0.0172; //毫米
H=100 - distance;
}
if(succeed_flag==0)
{
distance=0; //没有回波则清零
}
a=H/100;
b=(H%100)/10;
c=H%10;
lcd_wcmd(0x06); //向右移动光标
lcd_pos(0); //设置显示位置为第一行的第1个字符
i = 0;
while(dis1[i] != '\0')
{ //显示字符
lcd_wdat(dis1[i]);
i++;
delay2(2); //控制两字之间显示速度
}
lcd_pos(0x45); //设置显示位置为第二行第1个字符
lcd_wdat(dis2[a]);
delay2(2);
lcd_wdat(dis2[b]);
delay2(2);
lcd_wdat(dis2[c]);
delay2(2);
lcd_wdat('c');
delay2(2);
lcd_wdat('m');
delay2(2);
if(distance>10)
motor_turn;
}
}
void exter() interrupt 0 // 外部中断0是0号
{
EX0=0; //关闭外部中断
timeH =TH1; //取出定时器的值
timeL =TL1; //取出定时器的值
succeed_flag=1;//至成功测量的标志
}
void timer1() interrupt 3 //
{
TH1=0;
TL1=0;
}
出现这种情况为什么MAIN.C(252): warning C275: expression with possibly no effect
这句话的意思是,表达式没有影响,就是说你警报的地方做了一次无意义的操作,看看你的运算符是不是搞错了。
if(distance>10)
motor_turn; //这一句 行数调用 忘了加括号 motor_turn();
今天运行一个以前的项目,突然出现了如下错误
原因是这个项目工程没有标志,
在Bundle identifier后面填上你的标识就行了,记得运行前Command+shift+k清空一下......
答案就在这里:iOS运行出现No application was specified.
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。