新手上路
- 积分
- 38
- 金钱
- 38
- 注册时间
- 2019-6-4
- 在线时间
- 11 小时
|
1金钱
#include <math.h>
#include "STC12C5A60S2.H"
# include <intrins.h>
#include "oled.h"
# define uchar unsigned char
# define uint unsigned int
sbit A=P0^4;
sbit BD=P0^5;
sbit C=P0^6;
sbit D=P0^7;
unsigned char SHU;
unsigned char temp;
/* -------------函数声明开始--------------- */
void init_adc(unsigned ChannelInit);
uint get_adc(unsigned Channel);
/* -------------函数声明结束--------------- */
typedef unsigned int u16;
sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;
unsigned char code wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//????????
unsigned char code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//0-f???
u8 disp[4];
u8 code smgduan[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(u16 i)
{
while(i--);
}
void datapros()
{
static u8 i;
if(i==50){
i=0;
temp =get_adc(1);
}
i++;
disp[0] = smgduan[temp/1000];
disp[1] = smgduan[temp%1000/100];
disp[2] = smgduan[temp%1000%100/10];
disp[3] = smgduan[temp%1000%100%10];
}
void DigDisplay()
{
u8 i;
for(i=0;i<4;i++){
switch(i){
case(0)SA=0;LSB=0;LSC=0;break;
case(1)SA=1;LSB=0;LSC=0;break;
case(2)SA=0;LSB=1;LSC=0;break;
case(3)SA=1;LSB=1;LSC=0;break;
}
P0 = disp[i];
delay(100);
P0 = 0x00;
}
}
void init_adc(unsigned ChannelInit)
{
P1ASF = ChannelInit; //AD功能寄存器,设置I/O口作为AD转换实用。使用P1.0口。
ADC_RES = 0; //清理结果寄存器的值
ADC_RESL = 0; //清理结果寄存器的值
ADC_CONTR = 0xA0; //开启AD电源并设置转换周期为540个时钟周期转换一次。
delay(3600);
}
uint get_adc(unsigned Channel)
{
uint d=0;
ADC_CONTR = 0X88|Channel;
_nop_();
_nop_();
_nop_();
_nop_();
while(!(ADC_CONTR & 0X10));
ADC_CONTR &= ~0X10;
d |= ADC_RES;
d <<= 2;
d |= ADC_RESL;
return d;
}
void BlueteethInit()
{
SM0=0;
SM1=1;
REN=1;
EA=1;
ES=1;
TMOD|=0X20;
TH1=0XFD;
TL1=0XFD;
TR1=1;
}
int a=1;
void main (void)
{
int h=0;
BlueteethInit();
init_adc(0x00);
while(1)
{
h=get_adc(0)/10;
SBUF=h;
while(!TI);
TI=0;
h=get_adc(1)/10+110;
SBUF=h;
while(!TI);
TI=0;
delay(500000);
}
}
这串代码貌似只能控制两轮同速的情况,我想要实现转弯,就必须分别控制左右轮的速度,分别控制就需要两个定时中断,定时器还要同时计时,请问应该如何改写代码来实现啊
|
|