#include <rtthread.h>
#include <rtdevice.h>
#include <stdlib.h>
#define DAC_DEV_NAME "dac1" /* DAC 设备名称 */
#define DAC_DEV_CHANNEL 1 /* DAC 通道 */
#define REFER_VOLTAGE 330 /* 参考电压 3.3V,数据精度乘以100保留2位小数*/
#define CONVERT_BITS (1 << 12) /* 转换位数为12位 */
static int dac_vol_sample(int argc, char *argv[])
{
rt_dac_device_t dac_dev;
rt_uint32_t value, vol;
rt_err_t ret = RT_EOK;
/* 查找设备 */
dac_dev = (rt_dac_device_t)rt_device_find(DAC_DEV_NAME);
if (dac_dev == RT_NULL)
{
rt_kprintf("dac sample run failed! can't find %s device!\n", DAC_DEV_NAME);
return RT_ERROR;
}
/* 打开通道 */
ret = rt_dac_enable(dac_dev, DAC_DEV_CHANNEL);
/* 设置输出值 */
value = atoi(argv[1]);
rt_dac_write(dac_dev, DAC_DEV_CHANNEL, &value);
rt_kprintf("the value is :%d \n", value);
/* 转换为对应电压值 */
vol = value * REFER_VOLTAGE / CONVERT_BITS;
rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100);
/* 延时查看效果,关闭通道后无输出 */
rt_thread_mdelay(500);
/* 关闭通道 */
ret = rt_dac_disabled(dac_dev, DAC_DEV_CHANNEL);
return ret;
}
就是说,这段DAC的使用是没有main函数的,如果不用MSH强行编译的话,是运行不了的,
就想问怎么写这个的main函数,怎么把dac_vol_sample这个函数写到main里?
msh中输入:
dac_vol_sample 1234
os会调用dac_vol_sample函数,并且,argc是2,agrv[0]是“dac_vol_sample”,agrv[1]是“1234”。
额。。。。我要是烧到芯片里,这个MSH好像用不了把,必须得要有一个main函数,咋写啊