#include "ti/devices/msp/m0p/mspm0g350x.h"
#include "ti_msp_dl_config.h"
#include "stdio.h"
#include "string.h"
void delay_ms(uint32_t ms);
void itoa1(int num,char str1[] );
void itoa2(int num,char str2[] );
void send_data1(int a);
void send_data2(int a);
volatile uint8_t aRxbffer=0;
int main(void)
{
SYSCFG_DL_init();
NVIC_ClearPendingIRQ(UART0_INT_IRQn);
NVIC_EnableIRQ(UART0_INT_IRQn);
while (1) {
if(aRxbffer==10){
send_data1(3300);
send_data2(2200);
}
}
}
int fputc(int c,FILE *stream)//print重定向
{
DL_UART_Main_transmitDataBlocking(UART_0_INST,c);
return c;
}
int fputs(const char* restrict s, FILE* restrict stream)
{
uint16_t i,len;
len = strlen(s);
for(i=0; i<len; i++)
{
DL_UART_Main_transmitDataBlocking(UART_0_INST,s[i]);
}
return len;
}
int puts(const char *_ptr)
{
int count = fputs(_ptr,stdout);
count += fputs("\n",stdout);
return count;
}
void send_data1(int a)//向串口发送数据
{
char str1[10];
itoa1(a,str1);
printf("page0.x0.val=");
printf("%s",str1);
printf("\xff\xff\xff");
delay_ms(100);
}
void send_data2(int a)
{
char str2[10];
itoa2(a,str2);
printf("page0.x1.val=");
printf("%s",str2);
printf("\xff\xff\xff");
delay_ms(100);
}void itoa1(int num,char str1[] )//转换为字符串
{
int sign = num,i = 0,j = 0;
char temp[11];
if(sign<0)
{
num = -num;
}
do
{
temp[i] = num%10+'0';
num/=10;
i++;
}while(num>0);
if(sign<0)
{
temp[i++] = '-';
}
temp[i] = '\0';
i--;
while(i>=0)
{
str1[j] = temp[i];
j++;
i--;
}
str1[j] = '\0';
}
void itoa2(int num,char str2[] )
{
int sign = num,i = 0,j = 0;
char temp2[11];
if(sign<0)
{
num = -num;
}
do
{
temp2[i] = num%10+'0';
num/=10;
i++;
}while(num>0);
if(sign<0)
{
temp2[i++] = '-';
}
temp2[i] = '\0';
i--;
while(i>=0)
{
str2[j] = temp2[i];
j++;
i--;
}
str2[j] = '\0';
}
void delay_ms(uint32_t ms)//延时函数
{
while (ms--) {
delay_cycles(CPUCLK_FREQ/1000);
}
}
void UART_0_INST_IRQHandler(void)
{
aRxbffer = DL_UART_Main_receiveData(UART_0_INST);
DL_UART_Main_transmitData(UART_0_INST, aRxbffer);
}