专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
TI
关于430f5529的IO
2019-07-17 15:26
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
TI MCU
18474
19
1487
使用p1.1按键输入,控制一个数字量a步进增加1,按键p2.1按键输入,a步进减1
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
19条回答
IOUJANE
2019-07-17 21:21
#include <msp430.h>
#include <msp430f5529.h>
/*
* main.c
*/
#define uint unsigned int
int codeArray[]={0x199,0xCC,0x88,0x66,0x51,0x51,0x44,0x3A,0x33,0x2D,0x28};
int i=0;
void spiwrite(int data12,int cmd)
{
int n,j;
int jj=cmd;
P3OUT |= 0x01; //SYNC高
for( n=0;n<200;n++);
P3OUT |= 0x02; //SCLK高
P3OUT &= ~0x01; //SYNC低 片选使能
for( n=0;n<200;n++);
for(j=0;j<4;j++)
{
for(n=0;n<100;n++);
P3OUT |= 0x02; //SCLK高
for(n=0;n<100;n++);
if((jj>>(3-j)) & 0x01)
P3OUT |= 0x04;//数据高电平
else
P3OUT &=~0x04;//数据低电平
for(n=0;n<100;n++);
P3OUT &= ~0x02; //SCLK低
}
for(j=0;j<12;j++)
{
for(n=0;n<100;n++);
P3OUT |= 0x02; //SCLK高
for(n=0;n<100;n++);
if((data12>>(11-j)) & 0x01)
P3OUT |= 0x04;//数据高电平
else
P3OUT &=~0x04;//数据低电平
for(n=0;n<100;n++);
P3OUT &= ~0x02; //SCLK低
}
for(n=0;n<100;n++);
P3OUT |= 0x02; //SCLK高
for(n=0;n<100;n++);
P3OUT |= 0x01; //SYNC高
for(n=0;n<200;n++);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR|=BIT0; //设置p1.0为输出
P1REN|=BIT1;
P1OUT|=BIT1;
P3OUT |= 0x07;//P3.0 - P3.2模拟SPI接口
P3DIR |= 0x07;//P3.0->SYNC,P3.1->SCLK,P3.2->SDIN
//int code=0x28; //衰减20db,100倍0x28.
//int code=0x800;
int code=codeArray[i];
int code1;
spiwrite(code,1);
while(1)
{
if(!(P1IN&0x02)){
delay(1);
if(!(P1IN&0x02)){
while(!(P1IN&0x02)){
P1OUT^=BIT0;
if(i<9)
i++;
code=codeArray[i];
}
}
}
code1 = code;
spiwrite(code1,1);
}
}
加载中...
查看其它19个回答
一周热门
更多
>
相关问题
CPLD的方波输出
4 个回答
11个版本Quartus II 软件下载,安装包网盘合集,附教程,47G!
20 个回答
请大家帮忙到21IC发展大家谈支持我申请新版面
20 个回答
【通知】21ic中国电子网服务条款 (所有人员必读)
1 个回答
满载而归乙亥年,大展鸿途庚子年---集签赢好礼
20 个回答
相关文章
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
TI
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
#include <msp430f5529.h>
/*
* main.c
*/
#define uint unsigned int
int codeArray[]={0x199,0xCC,0x88,0x66,0x51,0x51,0x44,0x3A,0x33,0x2D,0x28};
int i=0;
void spiwrite(int data12,int cmd)
{
int n,j;
int jj=cmd;
P3OUT |= 0x01; //SYNC高
for( n=0;n<200;n++);
P3OUT |= 0x02; //SCLK高
P3OUT &= ~0x01; //SYNC低 片选使能
for( n=0;n<200;n++);
for(j=0;j<4;j++)
{
for(n=0;n<100;n++);
P3OUT |= 0x02; //SCLK高
for(n=0;n<100;n++);
if((jj>>(3-j)) & 0x01)
P3OUT |= 0x04;//数据高电平
else
P3OUT &=~0x04;//数据低电平
for(n=0;n<100;n++);
P3OUT &= ~0x02; //SCLK低
}
for(j=0;j<12;j++)
{
for(n=0;n<100;n++);
P3OUT |= 0x02; //SCLK高
for(n=0;n<100;n++);
if((data12>>(11-j)) & 0x01)
P3OUT |= 0x04;//数据高电平
else
P3OUT &=~0x04;//数据低电平
for(n=0;n<100;n++);
P3OUT &= ~0x02; //SCLK低
}
for(n=0;n<100;n++);
P3OUT |= 0x02; //SCLK高
for(n=0;n<100;n++);
P3OUT |= 0x01; //SYNC高
for(n=0;n<200;n++);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR|=BIT0; //设置p1.0为输出
P1REN|=BIT1;
P1OUT|=BIT1;
P3OUT |= 0x07;//P3.0 - P3.2模拟SPI接口
P3DIR |= 0x07;//P3.0->SYNC,P3.1->SCLK,P3.2->SDIN
//int code=0x28; //衰减20db,100倍0x28.
//int code=0x800;
int code=codeArray[i];
int code1;
spiwrite(code,1);
while(1)
{
if(!(P1IN&0x02)){
delay(1);
if(!(P1IN&0x02)){
while(!(P1IN&0x02)){
P1OUT^=BIT0;
if(i<9)
i++;
code=codeArray[i];
}
}
}
code1 = code;
spiwrite(code1,1);
}
}
一周热门 更多>