【ufun学习】环境开发搭建
<div class='showpostmsg'> 本帖最后由 闵丨大 于 2019-7-21 16:41 编辑<p><b><font color="#5E7384">此内容由EEWORLD论坛网友<font size="3">闵丨大</font>原创,如需转载或用于商业用途需征得作者同意并注明出处</font></b><br />
<span style="font-size:20px"><span style="font-family:宋体"> 小弟跟着师兄准备全国电赛,师兄让我学习TI公司的MSP430F5529单片机。所以没能及时更新,非常抱歉。另外,当时以为自己下单了ST-Link,今天才发现并没有下单,超级尴尬。下文通过ISP烧写代码的方式到ufun。</span></span></p>
<p><span style="font-size:20px"><span style="font-family:宋体"> 本文根据张先生提供的《uFun快速入门手册》和ufun原理图进行学习。文末会有ufun资料下载链接。</span></span></p>
<p><span style="font-size:20px"><span style="font-family:宋体"> 1.安装KEIL5。</span></span></p>
<p><span style="font-size:20px"><span style="font-family:宋体"> 2.ISP下载:<a href="https://www.stmcu.com.cn" style="color:#0563c1; text-decoration:underline">https://www.stmcu.com.cn</a>搜索Flash Loader Demonstrator</span></span></p>
<p></p>
<p></p>
<p></p>
<p><span style="font-size:20px"><span style="font-family:宋体">安装完成。</span></span></p>
<p></p>
<p><span style="font-size:20px"><span style="font-family:宋体">NEXT</span></span></p>
<p></p>
<p style="margin-left:24px; text-indent:0cm; text-align:justify"><span style="font-size:20px"><span style="font-family:宋体">中文意思:不能识别驱动,请复位你的设备,然后再尝试。</span></span></p>
<p style="margin-left:24px; text-indent:0cm; text-align:justify"><span style="font-size:20px"><span style="font-family:宋体"><b><span style="color:red">原因:</span></b></span></span><span style="font-size:20px"><span style="font-family:宋体">BOOT0没有设置为’1’。用短接片将牛角座上BOOT0脚和VCC_3V3连接。</span></span><span style="font-size:20px"><span style="font-family:宋体">当时忘记短接(捂脸)</span></span></p>
<p style="margin-left:24px; text-indent:0cm; text-align:justify"></p>
<p style="text-align:justify"><span style="font-size:20px"><span style="font-family:宋体"> 3.通过ISP烧写代码</span></span></p>
<p style="text-align:justify"><span style="font-size:20px"><span style="font-family:宋体"> 4.例程1—三色LED灯闪烁。1s切换一次颜色。</span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> 5.例程2—PWM控制LED灯闪烁</span></span></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> 6.例程3—蜂鸣器控制</span></span></p>
<p style="text-align:justify"></p>
<table align="center" border="1" cellpadding="1" cellspacing="1" class="center-class" style="width: 100%;">
<tbody>
<tr>
<td>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">void BEEP_Init(void)</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线">{</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"> GPIO_InitTypeDef GPIO_InitStructure;</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"> </span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //ʹÄÜPA¶Ë¿ÚʱÖÓ</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"> </span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //·äÃùÆ÷Òý½Å¶¨Òå</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"> GPIO_Init(GPIOA, &GPIO_InitStructure);//³õʼ»¯GPIO</span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"> GPIO_SetBits(GPIOA, GPIO_Pin_8);</span></span></p>
<p style="text-align:justify"><span style="font-family: 等线; font-style: italic; text-align: center;">}</span></p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p> </p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> 7.例程4—USB串口与PC通讯</span></span></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> 8.例程5—触摸按钮控制</span></span></p>
<p style="margin-left:24px; text-indent:0cm; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> 8.1按钮控制—俄罗斯方块</span></span></p>
<p style="margin-left:24px; text-indent:0cm; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"></span></span></p>
<p style="list-style-type:none"><span style="font-size:20px;"><span style="font-family:宋体;"> 8.2按钮控制—PWM</span></span></p>
<p style="margin-left:25px; text-indent:0cm; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;">问题1:下按键不能够变换颜色。</span></span></p>
<p style="margin-left:25px; text-indent:0cm; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;">问题2:按钮长按没反应</span></span></p>
<p style="margin-left:25px; text-indent:0cm; text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> 9.例程6—ADC采集光敏电阻</span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;">问题1:只能16进制显示吗,不直观,若点击文本显示则出现乱码</span></span></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><br />
<span style="font-size:20px;"><span style="font-family:宋体;"></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> 10.例程7—三轴加速度传感器</span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"><strong><span style="font-size:20px;"><span style="font-family:宋体;"> 总结:资料包提供的7个例程代码每个都烧写到uFun中测试了一遍。存在3个疑惑,本人会尽快弄清楚问题出在哪里。</span></span></strong></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> 具体问题如下:</span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;">1.例程5中按钮控制PWM。下按钮不能变换颜色;按钮长按没有反应。</span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;">2.例程6中串口通信显示只能是16进制,若切换成文本模式则出现乱码。</span></span></p>
<p style="text-align:justify"></p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>由于资料包太大上传不了,只能上传到网盘上。</p>
<p>链接:https://pan.baidu.com/s/1KQevjMgsnW9uC3pZnEwyEg <br />
提取码:vait </p>
<p>续上帖两个问题。</p>
<p style="text-align:justify"><span style="background-color:white"><span style="color:#333333">1.</span><span style="color:#333333">例程5中按钮控制PWM。下按钮不能变换颜色;按钮长按没有反应。</span></span></p>
<p style="text-align:justify"><span style="background-color:white"><span style="color:#333333">2.</span><span style="color:#333333">例程6中串口通信显示只能是16进制,若切换成文本模式则出现乱码。</span></span></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify">问题1已解决。下按钮模式选择是指按键长按有效或短按有效。关键代码如下:</p>
<table align="center" border="1" cellpadding="1" cellspacing="1" style="width:100%">
<tbody>
<tr>
<td>
<p style="text-align:justify">//主函数部分</p>
<p style="text-align:justify">if(key_value==3) //检测到touch2被按下</p>
<p style="text-align:justify"> { </p>
<p style="text-align:justify"> if(mode==0) //按键模式切换,mode=0为关闭连续按键,mode=1位开启连续按键</p>
<p style="text-align:justify"> { </p>
<p style="text-align:justify"> mode=1; </p>
<p style="text-align:justify"> while(TOUCH2); //如果按键未抬起,阻塞,直到抬起,防止模式跳变</p>
<p style="text-align:justify"> } </p>
<p style="text-align:justify"> else </p>
<p style="text-align:justify"> mode=0; </p>
<p style="text-align:justify"> } </p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> } </p>
<p>}</p>
</td>
</tr>
</tbody>
</table>
<table align="center" border="1" cellpadding="1" cellspacing="1" style="width:100%">
<tbody>
<tr>
<td>
<p>//按键子函数部分</p>
<p style="text-align:justify">int Key_Scan(int mode) //按键扫描函数</p>
<p style="text-align:justify">{</p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> <strong>if(mode==1) //</strong><strong>按键模式切换,mode为1时长按按键可被多次连续识别,为0时长按按键视为单次按键</strong></p>
<p style="text-align:justify"><strong> {</strong></p>
<p style="text-align:justify"><strong> key_up=1;</strong></p>
<p style="text-align:justify"><strong> }</strong></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> if(key_up==1&&(TOUCH0==1||TOUCH1==1||TOUCH2==1||TOUCH3==1))//不同的按键被按下返还不同的值</p>
<p style="text-align:justify"> {</p>
<p style="text-align:justify"> Delay_Ms(100);</p>
<p style="text-align:justify"> key_up=0;</p>
<p style="text-align:justify"> if(TOUCH0 == 1) </p>
<p style="text-align:justify"> return 1;</p>
<p style="text-align:justify"> if(TOUCH1 == 1) </p>
<p style="text-align:justify"> return 2;</p>
<p style="text-align:justify"> if(TOUCH2 == 1) </p>
<p style="text-align:justify"> return 3;</p>
<p style="text-align:justify"> if(TOUCH3 == 1) </p>
<p style="text-align:justify"> return 4;</p>
<p style="text-align:justify"> }</p>
<p style="text-align:justify"> else if(TOUCH0==0&&TOUCH1==0&&TOUCH2==0&&TOUCH3==0)</p>
<p style="text-align:justify"> {</p>
<p style="text-align:justify"> key_up=1;</p>
<p style="text-align:justify"> }</p>
<p style="text-align:justify"> return 0;</p>
<p>}</p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p style="text-align:justify">问题2….</p>
<p>我想改成显示真实电压值,修改部分如下但不成功,望不吝赐教!</p>
<table align="center" border="1" cellpadding="1" cellspacing="1" style="width:100%">
<tbody>
<tr>
<td>
<p style="text-align:justify">while(1)</p>
<p style="text-align:justify"> {</p>
<p style="text-align:justify"> Delay_Ms(100);</p>
<p style="text-align:justify"> sprintf((char *)dtbuf,"光敏电阻电压值:\r\n");</p>
<p style="text-align:justify"> ADC_Value_1=(int)ADC_Value*1000; //ADC_Value值为ADC模块转换后的数值</p>
<p style="text-align:justify"> ADC_Value_a=(ADC_Value_1/1000)%10;</p>
<p style="text-align:justify"> ADC_Value_b=(ADC_Value_1/100)%10;</p>
<p style="text-align:justify"> ADC_Value_c=(ADC_Value_1/10)%10;</p>
<p style="text-align:justify"> ADC_Value_d=(ADC_Value_1/1)%10;</p>
<p style="text-align:justify"> // Usart_SendString( USART1,dtbuf);//将ADC_Value通过USART1发送</p>
<p style="text-align:justify"> Usart_SendByte( USART1,ADC_Value_a);//个位</p>
<p style="text-align:justify"> Usart_SendByte( USART1,'.');//</p>
<p style="text-align:justify"> Usart_SendByte( USART1,ADC_Value_b);//十分位</p>
<p style="text-align:justify"> Usart_SendByte( USART1,ADC_Value_c);//百分位</p>
<p style="text-align:justify"> Usart_SendByte( USART1,ADC_Value_d);//千分位</p>
<p style="text-align:justify"> }</p>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</tbody>
</table>
<p> </p>
<p>谢谢分享经验,列出了一下踩得坑,学习借鉴。点赞<img height="50" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/onion/Onion--112.gif" width="50" /></p>
<p>为什么我移植串口程序的时候,总是乱码,但是用原来的例程烧写进去又没事了呢?</p>
<p>我的总线时钟没配置明白吗?</p>
<p>我看代码里面也没有配置总线时钟的语句呀</p>
<p>有的,但是不在主函数内。具体位置我有些记不清了。</p>
页:
[1]