S32K144CAN,ADC,驱动源码
单片机源程序如下:
#include "include.h"
uint8_t TIME0flag_5ms ;
uint8_t TIME0flag_10ms ;
uint8_t TIME0flag_20ms ;
uint8_t TIME0flag_50ms ;
uint8_t TIME0flag_80ms ;
uint8_t TIME0flag_100ms ;
uint8_t flag;
uint16_t ADRESULT;
uint8_t CANTXdata0[8]={0X11,0X22,0X33,0X44,0X55,0X66,0X77,0X88};
uint8_t RXData0[8];
uint32_t ID0;
uint8_t Datalen0;
uint8_t flag0;
int main(void)
{
__disable_irq(); //关闭总中断
SystemCoreClockSet(); //系统时钟初始化
GPIO_Clock_Enable (); //GPIO端口时钟使能
PIT_Init_ms(PIT0,500); //周期定时器PIT0初始化,500ms
ADC_Init(SADC1, AD6) ; //ADC1_CH6通道初始化
CAN_Init(CAN0CH, 250) ; //CAN0通道初始化,250K
GPIO_Init(PTD0, GPO, 0);
GPIO_Init(PTD1, GPO, 0);
GPIO_Set(PTD0, 0);
GPIO_Set(PTD1, 0);
__enable_irq() ; //开启总中断
while(1)
{
ADRESULT=ADC_Ave(SADC1, AD6, ADC_12bit, 4); //采集ADC1_CH6通道电压
flag0=CAN_RecData(CAN0CH, &ID0, &Datalen0, RXData0);
if(TIME0flag_5ms) //500ms时间到标志
{
TIME0flag_5ms = 0 ;
CAN_SendData(CAN0CH, 1, 0X12345678, 8, RXData0); //CAN0通道发送数据
}
}
} |