新手上路
- 积分
- 34
- 金钱
- 34
- 注册时间
- 2019-11-12
- 在线时间
- 6 小时
|

楼主 |
发表于 2019-12-19 11:10:03
|
显示全部楼层
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "kk.h"
//#include "dac.h"
#include "can.h"
#include "timer.h"
extern u8 canrxbuf[8];
extern u8 canrxid;
extern int x;
extern int t;
int main(void)
{
u8 mode=0; //普通模式
Stm32_Clock_Init(9); //系统时钟设置
uart_init(72,115200); //串口初始化为115200
delay_init(72); //延时初始化
LED_Init(); //初始化与LED连接的硬件接口
// Dac1_Init();
// Dac2_Init();
CAN_Mode_Init(1,8,9,8,mode);//CAN 初始化,波特率 250Kbps 36M/((1+8+9)*8)=250kbps
KK_Init(); //OUT初始化
TIM3_Int_Init(99,7199); //定时器3 100*7200/72=10ms
while(1)
{
if(canrxid==0x23)
{
if(canrxbuf[0]==0x04) //机具下降
{
KG1=1;
t=0; //定时器中断清零
if(t==500) //5s后停止输出
{
KG1=0;
canrxbuf[0]=0x00;
}
}
if(canrxbuf[0]==0x08) //机具上升
{
KG2=1;
x=0; //定时器中断清零
if(x==500)
{
KG2=0;
canrxbuf[0]=0x00; //重置
}
}
if(canrxbuf[2]==0x10)
{
KG3=1;
}
if(canrxbuf[2]==0x00)
{
KG3=0;
}
}
LED2=!LED2;
delay_ms(200);
}
}
重新上传一下。 |
|