专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
TI
MSP430F5529红外模块发送程序
2019-07-16 15:15
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
TI MCU
6970
19
1059
#include <msp430.h>
#define CPU_F ((double)1000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
int cnt;
volatile int iflag=0;
void ir_open(){
iflag=0;
P2DIR |= BIT3;//P2.2, P2.3输出
P2SEL &= ~BIT3; //P2.2:IO P2.3:TA0
P2OUT &= ~BIT3;
//38K->P2.3
TBCCR0=15;
/*TBCCR0 = (int)(26.3*8 + 0.5);`
TBCCTL0 = OUTMOD_6;
TBCCR1 = (int)(13.15*8 + 0.5);
*/
TBCTL = TASSEL_2+MC_1+TACLR;
TBCCTL0=CCIE;
}
void ir_start(){
P2OUT |= BIT3;
iflag=1;
delay_us(9000);
TBCTL =MC_1;
P2OUT &= ~BIT3;
iflag=0;
delay_us(4500);
TBCTL =MC_0;
}
void ir_next(){
P2OUT |= BIT3;
iflag=1;
delay_us(9000);
P2OUT &= ~BIT3;
iflag=0;
delay_us(2250);
}
void ir_send_byte(unsigned char c){
unsigned char i;
for(i = 0; i != 8; ++i){
P2OUT |= BIT3;
iflag=1;
delay_us(560);
P2OUT &= ~BIT3;
iflag=0;
if(c&0x01){
delay_us(1685);
}
else{
delay_us(565);
}
c >>= 1;
}
}
void ir_end(){
P2OUT |= BIT3;
iflag=1;
delay_us(300);
P2OUT &= ~BIT3;
iflag=0;
}
void ir_put(unsigned char c){
ir_start();
ir_send_byte(0x00);
ir_send_byte(0x90);
ir_send_byte(0x04);
ir_send_byte(0x0A);
ir_end();
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |=BIT0 ; // P1.0 output
while(1)
{
//yanshi 1s
/* cnt = 1000;
TA0CCTL0 = ~CCIE;
while(cnt!= 0);
P1OUT ^= BIT0;
TA1CTL = MC_0; //mc_0=stop*/
P1OUT ^= BIT0;
ir_open();
__bis_SR_register(GIE);
ir_put(0x83);
}
}
//#pragma vector = TIMERB_A0_VECTOR
#pragma vector=TIMERB0_VECTOR
__interrupt void TIMERB0_ISR()
{
if(iflag==1);
P2OUT ^= BIT3;
}
复制代码
请问问这程序有什么问题,38KHZ,我的定时器计时应该是13.8usIO电平翻转一次,但是
定时15之后进了中断之后就出不了,css不熟也不知道应该怎么调试,求大牛指点
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
19条回答
dirtwillfly
1楼-- · 2019-07-16 20:57
ccs的使用参考:
Code_Composer_Studio(CCS)集成开发环境(IDE)入门指导书V10.pdf
(3.74 MB, 下载次数: 8)
2017-6-23 08:10 上传 点击文件名下载附件
加载中...
eziobro
2楼-- · 2019-07-16 23:16
提高时钟频率16MHZ搞定 我有空再来上传代码
加载中...
dirtwillfly
3楼-- · 2019-07-17 00:13
精彩回答 2 元偷偷看……
加载中...
fentianyou
4楼-- · 2019-07-17 02:59
这个 MSP430F5529能用?
加载中...
fentianyou
5楼-- · 2019-07-17 07:13
MSP430F5529的头文件不是msp430f55xx吗?
加载中...
eziobro
6楼-- · 2019-07-17 10:57
#include <msp430.h>
#define CPU_F ((double)16000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
int cnt,key=0,TEMP=0,times=0;
volatile int iflag=0;
void key_init(){
P1DIR |= BIT7;
P1REN |= BIT7;
P1IFG &= ~ BIT7;
P1IES |= BIT7;
P1IE |= BIT7;
P2DIR &= ~ BIT2 ;
P2REN |= BIT2;//Connects to the resistance
P2OUT |= BIT2;//Pull-Up Resistance
P2IES |= BIT2;
P2IFG &= ~ BIT2;
P2IE |= BIT2;
}
void ir_open(){
iflag=0;
P2DIR |= BIT3;//P2.2, P2.3Êä³ö
P2SEL &= ~BIT3; //P2.2:IO P2.3:TA0
P2OUT &= ~BIT3;
//38K->P2.3
//TBCCR0=15;
TBCCR0=210;
TBCTL = TASSEL_2+MC_1+TACLR;
TBCCTL0=CCIE;
}
void ir_start(){
P2OUT |= BIT3;
iflag=1;
delay_us(9000);
//TBCTL =MC_1;
P2OUT &= ~BIT3;
iflag=0;
delay_us(4500);
//TBCTL =MC_0;
}
void ir_next(){
P2OUT |= BIT3;
iflag=1;
delay_us(9000);
P2OUT &= ~BIT3;
iflag=0;
delay_us(2250);
}
void ir_send_byte(unsigned char c){
unsigned char i;
for(i = 0; i != 8; ++i){
P2OUT |= BIT3;
iflag=1;
delay_us(560);
P2OUT &= ~BIT3;
iflag=0;
if(c&0x01){
delay_us(1685);
}
else{
delay_us(565);
}
c >>= 1;
}
}
void ir_send_3byte(unsigned char c){
unsigned char i;
for(i = 0; i !=3; ++i){
P2OUT |= BIT3;
iflag=1;
delay_us(560);
P2OUT &= ~BIT3;
iflag=0;
if(c&0x01){
delay_us(1685);
}
else{
delay_us(565);
}
c >>= 1;
}
}
void ir_end(){
P2OUT &= ~BIT3;
iflag=0;
delay_us(300);
P2OUT |= BIT3;
iflag=1;
}
void ir_put_temp(unsigned char c){
ir_start();
ir_send_byte(0x79);
ir_send_byte(0x0e);
ir_send_byte(0x30);
ir_send_byte(0x50);
ir_send_3byte(0x02);
P2OUT |= BIT3;
iflag=1;
delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_us(19700);
ir_send_byte(0x10);
ir_send_byte(0x21);
ir_send_byte(0x00);
ir_send_byte(0x10);
//P2OUT |= BIT3;
//iflag=1;
//delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_ms(2000);
//ir_end();
}
void ir_put(unsigned char c){
ir_start();
ir_send_byte(0x00);
ir_send_byte(0x09);
ir_send_byte(0x20);
ir_send_byte(0x50);
ir_send_3byte(0x02);
P2OUT |= BIT3;
iflag=1;
delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_us(19700);
ir_send_byte(0x00);
ir_send_byte(0x20);
ir_send_byte(0x00);
ir_send_byte(c);
P2OUT |= BIT3;
iflag=1;
delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_ms(2000);
//ir_end();
}
void ir_put_on(unsigned char c){
ir_start();
ir_send_byte(0x79);
ir_send_byte(0x00);
ir_send_byte(0x30);
ir_send_byte(0x50);
ir_send_3byte(0x02);
P2OUT |= BIT3;
iflag=1;
delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_us(19700);//19700
ir_send_byte(0x10);
ir_send_byte(0x21);
ir_send_byte(0x00);
ir_send_byte(0x30);
P2OUT &= ~BIT3;
iflag=0;
delay_ms(2000);
//ir_end();
}
int main(void)
{
__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL1 = DCORSEL_5; // Select DCO range 16MHz operation
UCSCTL2 |= 499; // Set DCO Multiplier for 16MHz
// (N + 1) * FLLRef = Fdco
// (249 + 1) * 32768 = 8MHz
__bic_SR_register(SCG0);
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |=BIT0 ; // P1.0 output
key_init();
ir_open();
__bis_SR_register(GIE);
while(1)
{
P1OUT ^= BIT0;
ir_put_on(16);//work!
times=1;
}
}
//#pragma vector = TIMERB_A0_VECTOR
#pragma vector=TIMERB0_VECTOR
__interrupt void TIMERB0_ISR()
{
if(iflag==1)
{
P2OUT ^= BIT3;
//P1OUT ^= BIT0;
}
}
#pragma vector = PORT1_VECTOR
__interrupt void Port1_IRS()
{
int state;
state=P1IN&BIT7;
delay_ms(500);
if(state==(P1IN&BIT7))
//irda_receive();
{
times=0;
P1OUT ^=BIT0;
TEMP=20;
}
P1IFG &= ~ BIT7 ;
}
#pragma vector = PORT2_VECTOR
__interrupt void Port2_IRS()
{
int state;
state=P2IN&BIT2;
delay_ms(500);
if(state==(P2IN&BIT2))
//irda_receive();
{
times=0;
P1OUT ^=BIT0;
key++;
if(key==3)
key=1;
}
P2IFG &= ~ BIT2 ;
}
//格力YBOF2,实现16度开空调。
加载中...
1
2
3
4
下一页
一周热门
更多
>
相关问题
CPLD的方波输出
4 个回答
11个版本Quartus II 软件下载,安装包网盘合集,附教程,47G!
20 个回答
请大家帮忙到21IC发展大家谈支持我申请新版面
20 个回答
【通知】21ic中国电子网服务条款 (所有人员必读)
1 个回答
满载而归乙亥年,大展鸿途庚子年---集签赢好礼
20 个回答
携手ADI,踏上电子工程师之巅—车辆电气化视频,答题领奖!
1 个回答
如何提升论坛质量,看你了!
20 个回答
【最终名单】二姨家喊你来拿100份新年大礼啦~
20 个回答
相关文章
×
关闭
采纳回答
向帮助了您的网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
TI
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
关闭
您已邀请
15
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
#define CPU_F ((double)16000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
int cnt,key=0,TEMP=0,times=0;
volatile int iflag=0;
void key_init(){
P1DIR |= BIT7;
P1REN |= BIT7;
P1IFG &= ~ BIT7;
P1IES |= BIT7;
P1IE |= BIT7;
P2DIR &= ~ BIT2 ;
P2REN |= BIT2;//Connects to the resistance
P2OUT |= BIT2;//Pull-Up Resistance
P2IES |= BIT2;
P2IFG &= ~ BIT2;
P2IE |= BIT2;
}
void ir_open(){
iflag=0;
P2DIR |= BIT3;//P2.2, P2.3Êä³ö
P2SEL &= ~BIT3; //P2.2:IO P2.3:TA0
P2OUT &= ~BIT3;
//38K->P2.3
//TBCCR0=15;
TBCCR0=210;
TBCTL = TASSEL_2+MC_1+TACLR;
TBCCTL0=CCIE;
}
void ir_start(){
P2OUT |= BIT3;
iflag=1;
delay_us(9000);
//TBCTL =MC_1;
P2OUT &= ~BIT3;
iflag=0;
delay_us(4500);
//TBCTL =MC_0;
}
void ir_next(){
P2OUT |= BIT3;
iflag=1;
delay_us(9000);
P2OUT &= ~BIT3;
iflag=0;
delay_us(2250);
}
void ir_send_byte(unsigned char c){
unsigned char i;
for(i = 0; i != 8; ++i){
P2OUT |= BIT3;
iflag=1;
delay_us(560);
P2OUT &= ~BIT3;
iflag=0;
if(c&0x01){
delay_us(1685);
}
else{
delay_us(565);
}
c >>= 1;
}
}
void ir_send_3byte(unsigned char c){
unsigned char i;
for(i = 0; i !=3; ++i){
P2OUT |= BIT3;
iflag=1;
delay_us(560);
P2OUT &= ~BIT3;
iflag=0;
if(c&0x01){
delay_us(1685);
}
else{
delay_us(565);
}
c >>= 1;
}
}
void ir_end(){
P2OUT &= ~BIT3;
iflag=0;
delay_us(300);
P2OUT |= BIT3;
iflag=1;
}
void ir_put_temp(unsigned char c){
ir_start();
ir_send_byte(0x79);
ir_send_byte(0x0e);
ir_send_byte(0x30);
ir_send_byte(0x50);
ir_send_3byte(0x02);
P2OUT |= BIT3;
iflag=1;
delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_us(19700);
ir_send_byte(0x10);
ir_send_byte(0x21);
ir_send_byte(0x00);
ir_send_byte(0x10);
//P2OUT |= BIT3;
//iflag=1;
//delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_ms(2000);
//ir_end();
}
void ir_put(unsigned char c){
ir_start();
ir_send_byte(0x00);
ir_send_byte(0x09);
ir_send_byte(0x20);
ir_send_byte(0x50);
ir_send_3byte(0x02);
P2OUT |= BIT3;
iflag=1;
delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_us(19700);
ir_send_byte(0x00);
ir_send_byte(0x20);
ir_send_byte(0x00);
ir_send_byte(c);
P2OUT |= BIT3;
iflag=1;
delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_ms(2000);
//ir_end();
}
void ir_put_on(unsigned char c){
ir_start();
ir_send_byte(0x79);
ir_send_byte(0x00);
ir_send_byte(0x30);
ir_send_byte(0x50);
ir_send_3byte(0x02);
P2OUT |= BIT3;
iflag=1;
delay_us(600);
P2OUT &= ~BIT3;
iflag=0;
delay_us(19700);//19700
ir_send_byte(0x10);
ir_send_byte(0x21);
ir_send_byte(0x00);
ir_send_byte(0x30);
P2OUT &= ~BIT3;
iflag=0;
delay_ms(2000);
//ir_end();
}
int main(void)
{
__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL1 = DCORSEL_5; // Select DCO range 16MHz operation
UCSCTL2 |= 499; // Set DCO Multiplier for 16MHz
// (N + 1) * FLLRef = Fdco
// (249 + 1) * 32768 = 8MHz
__bic_SR_register(SCG0);
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |=BIT0 ; // P1.0 output
key_init();
ir_open();
__bis_SR_register(GIE);
while(1)
{
P1OUT ^= BIT0;
ir_put_on(16);//work!
times=1;
}
}
//#pragma vector = TIMERB_A0_VECTOR
#pragma vector=TIMERB0_VECTOR
__interrupt void TIMERB0_ISR()
{
if(iflag==1)
{
P2OUT ^= BIT3;
//P1OUT ^= BIT0;
}
}
#pragma vector = PORT1_VECTOR
__interrupt void Port1_IRS()
{
int state;
state=P1IN&BIT7;
delay_ms(500);
if(state==(P1IN&BIT7))
//irda_receive();
{
times=0;
P1OUT ^=BIT0;
TEMP=20;
}
P1IFG &= ~ BIT7 ;
}
#pragma vector = PORT2_VECTOR
__interrupt void Port2_IRS()
{
int state;
state=P2IN&BIT2;
delay_ms(500);
if(state==(P2IN&BIT2))
//irda_receive();
{
times=0;
P1OUT ^=BIT0;
key++;
if(key==3)
key=1;
}
P2IFG &= ~ BIT2 ;
}
//格力YBOF2,实现16度开空调。
一周热门 更多>