5081|9

9795

帖子

24

TA的资源

版主

楼主
 

谁发的贴子最漂亮?敢来拼一拼吗? [复制链接]

本帖最后由 littleshrimp 于 2016-3-24 13:05 编辑

还在抱怨发不出漂亮的代码吗?

还在抱怨上传图片麻烦吗?

谁发的贴子最漂亮?

谁的方法最简单?

敢不敢来比一比?

敢不敢,敢不敢?

 

//******************************************************************************

//  MSP430G2xx3 Demo - Timer_A, Ultra-Low Pwr UART 9600 Echo, 32kHz ACLK

//

//  Description: Use Timer_A CCR0 hardware output modes and SCCI data latch

//  to implement UART function @ 9600 baud. Software does not directly read and

//  write to RX and TX pins, instead proper use of output modes and SCCI data

//  latch are demonstrated. Use of these hardware features eliminates ISR

//  latency effects as hardware insures that output and input bit latching and

//  timing are perfectly synchronised with Timer_A regardless of other

//  software activity. In the Mainloop the UART function readies the UART to

//  receive one character and waits in LPM3 with all activity interrupt driven.

//  After a character has been received, the UART receive function forces exit

//  from LPM3 in the Mainloop which configures the port pins (P1 & P2) based

//  on the value of the received byte (i.e., if BIT0 is set, turn on P1.0).

 

//  ACLK = TACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO

//  //* An external watch crystal is required on XIN XOUT for ACLK *// 

//

//               MSP430G2xx3

//            -----------------

//        /|\|              XIN|-

//         | |                 | 32kHz

//         --|RST          XOUT|-

//           |                 |

//           |   CCI0B/TXD/P1.1|-------->

//           |                 | 9600 8N1

//           |   CCI0A/RXD/P1.2|<--------

//

//  D. Dang

//  Texas Instruments Inc.

//  December 2010

//   Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10

//******************************************************************************

 

#include "msp430g2553.h"

 

//------------------------------------------------------------------------------

// Hardware-related definitions

//------------------------------------------------------------------------------

#define UART_TXD   0x02                     // TXD on P1.1 (Timer0_A.OUT0)

#define UART_RXD   0x04                     // RXD on P1.2 (Timer0_A.CCI1A)

 

//------------------------------------------------------------------------------

// Conditions for 9600 Baud SW UART, SMCLK = 1MHz

//------------------------------------------------------------------------------

#define UART_TBIT_DIV_2     (1000000 / (9600 * 2))

#define UART_TBIT           (1000000 / 9600)

 

//------------------------------------------------------------------------------

// Global variables used for full-duplex UART communication

//------------------------------------------------------------------------------

unsigned int txData;                        // UART internal variable for TX

unsigned char rxBuffer;                     // Received UART character

 

//------------------------------------------------------------------------------

// Function prototypes

//------------------------------------------------------------------------------

void TimerA_UART_init(void);

void TimerA_UART_tx(unsigned char byte);

void TimerA_UART_print(char *string);

 

//------------------------------------------------------------------------------

// main()

//------------------------------------------------------------------------------

void main(void)

{

    WDTCTL = WDTPW + WDTHOLD;               // Stop watchdog timer

 

    DCOCTL = 0x00;                          // Set DCOCLK to 1MHz

    BCSCTL1 = CALBC1_1MHZ;

    DCOCTL = CALDCO_1MHZ;

 

    P1OUT = 0x00;                           // Initialize all GPIO

    P1SEL = UART_TXD + UART_RXD;            // Timer function for TXD/RXD pins

    P1DIR = 0xFF & ~UART_RXD;               // Set all pins but RXD to output

    P2OUT = 0x00;

    P2SEL = 0x00;

    P2DIR = 0xFF;

 

    __enable_interrupt();

   

    TimerA_UART_init();                     // Start Timer_A UART

    TimerA_UART_print("G2xx2 TimerA UART\r\n");

    TimerA_UART_print("READY.\r\n");

   

    for (;;)

    {

        // Wait for incoming character

        __bis_SR_register(LPM0_bits);

       

        // Update board outputs according to received byte

        if (rxBuffer & 0x01) P1OUT |= 0x01; else P1OUT &= ~0x01;    // P1.0

        if (rxBuffer & 0x02) P1OUT |= 0x08; else P1OUT &= ~0x08;    // P1.3

        if (rxBuffer & 0x04) P1OUT |= 0x10; else P1OUT &= ~0x10;    // P1.4

        if (rxBuffer & 0x08) P1OUT |= 0x20; else P1OUT &= ~0x20;    // P1.5

        if (rxBuffer & 0x10) P1OUT |= 0x40; else P1OUT &= ~0x40;    // P1.6

        if (rxBuffer & 0x20) P1OUT |= 0x80; else P1OUT &= ~0x80;    // P1.7

        if (rxBuffer & 0x40) P2OUT |= 0x40; else P2OUT &= ~0x40;    // P2.6

        if (rxBuffer & 0x80) P2OUT |= 0x80; else P2OUT &= ~0x80;    // P2.7

       

        // Echo received character

        TimerA_UART_tx(rxBuffer);

    }

}

//------------------------------------------------------------------------------

// Function configures Timer_A for full-duplex UART operation

//------------------------------------------------------------------------------

void TimerA_UART_init(void)

{

    TACCTL0 = OUT;                          // Set TXD Idle as Mark = '1'

    TACCTL1 = SCS + CM1 + CAP + CCIE;       // Sync, Neg Edge, Capture, Int

    TACTL = TASSEL_2 + MC_2;                // SMCLK, start in continuous mode

}

//------------------------------------------------------------------------------

// Outputs one byte using the Timer_A UART

//------------------------------------------------------------------------------

void TimerA_UART_tx(unsigned char byte)

{

    while (TACCTL0 & CCIE);                 // Ensure last char got TX'd

    TACCR0 = TAR;                           // Current state of TA counter

    TACCR0 += UART_TBIT;                    // One bit time till first bit

    TACCTL0 = OUTMOD0 + CCIE;               // Set TXD on EQU0, Int

    txData = byte;                          // Load global variable

    txData |= 0x100;                        // Add mark stop bit to TXData

    txData <<= 1;                           // Add space start bit

}

 

//------------------------------------------------------------------------------

// Prints a string over using the Timer_A UART

//------------------------------------------------------------------------------

void TimerA_UART_print(char *string)

{

    while (*string) {

        TimerA_UART_tx(*string++);

    }

}

//------------------------------------------------------------------------------

// Timer_A UART - Transmit Interrupt Handler

//------------------------------------------------------------------------------

#pragma vector = TIMER0_A0_VECTOR

__interrupt void Timer_A0_ISR(void)

{

    static unsigned char txBitCnt = 10;

 

    TACCR0 += UART_TBIT;                    // Add Offset to CCRx

    if (txBitCnt == 0) {                    // All bits TXed?

        TACCTL0 &= ~CCIE;                   // All bits TXed, disable interrupt

        txBitCnt = 10;                      // Re-load bit counter

    }

    else {

        if (txData & 0x01) {

          TACCTL0 &= ~OUTMOD2;              // TX Mark '1'

        }

        else {

          TACCTL0 |= OUTMOD2;               // TX Space '0'

        }

        txData >>= 1;

        txBitCnt--;

    }

}     

//------------------------------------------------------------------------------

// Timer_A UART - Receive Interrupt Handler

//------------------------------------------------------------------------------

#pragma vector = TIMER0_A1_VECTOR

__interrupt void Timer_A1_ISR(void)

{

    static unsigned char rxBitCnt = 8;

    static unsigned char rxData = 0;

 

    switch (__even_in_range(TA0IV, TA0IV_TAIFG)) { // Use calculated branching

        case TA0IV_TACCR1:                        // TACCR1 CCIFG - UART RX

            TACCR1 += UART_TBIT;                 // Add Offset to CCRx

            if (TACCTL1 & CAP) {                 // Capture mode = start bit edge

                TACCTL1 &= ~CAP;                 // Switch capture to compare mode

                TACCR1 += UART_TBIT_DIV_2;       // Point CCRx to middle of D0

            }

            else {

                rxData >>= 1;

                if (TACCTL1 & SCCI) {            // Get bit waiting in receive latch

                    rxData |= 0x80;

                }

                rxBitCnt--;

                if (rxBitCnt == 0) {             // All bits RXed?

                    rxBuffer = rxData;           // Store in global variable

                    rxBitCnt = 8;                // Re-load bit counter

                    TACCTL1 |= CAP;              // Switch compare to capture mode

                    __bic_SR_register_on_exit(LPM0_bits);  // Clear LPM0 bits from 0(SR)

                }

            }

            break;

    }

}

//------------------------------------------------------------------------------

 

 

 

 

划到一个位置: 设置一个数值: 选择一个颜色: 选择一个日期:

最新回复

楼主给个教程呢  详情 回复 发表于 2016-4-6 10:31

赞赏

1

查看全部赞赏

点赞 关注
个人签名虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 

回复
举报

1万

帖子

25

TA的资源

版主

沙发
 
又是用什么好软件做的?
 
 
 

回复

1万

帖子

203

TA的资源

管理员

板凳
 
o(≧v≦)o~~好棒~~快来出个教程怎么弄的
加EE小助手好友,
入技术交流群
EE服务号
精彩活动e手掌握
EE订阅号
热门资讯e网打尽
聚焦汽车电子软硬件开发
认真关注技术本身
个人签名玩板看这里:
https://bbs.eeworld.com.cn/elecplay.html
EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!
 
 
 

回复

846

帖子

0

TA的资源

纯净的硅(中级)

4
 
楼主怎么搞出来的,还带自己上色功能,很不错的!赶快上正题吧!
 
 
 

回复

5979

帖子

8

TA的资源

版主

5
 

虾哥威武
个人签名生活就是油盐酱醋再加一点糖,快活就是一天到晚乐呵呵的忙
===================================
做一个简单的人,踏实而务实,不沉溺幻想,不庸人自扰
 
 
 

回复

429

帖子

84

TA的资源

纯净的硅(初级)

6
 
这个应该要好好学学
 
 
 

回复

714

帖子

2

TA的资源

一粒金砂(高级)

7
 
那盘虾看着不错
个人签名Hello astroturfers
 
 
 

回复

4177

帖子

9

TA的资源

五彩晶圆(高级)

8
 
之前看msp430官网的例程文件的注释是这样的注释,下面的这个是啥高端的软件做的额?
 
 
 

回复

2721

帖子

0

TA的资源

纯净的硅(中级)

9
 
看着看着出来一盘虾
 
 
 

回复

429

帖子

84

TA的资源

纯净的硅(初级)

10
 
楼主给个教程呢
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/7 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表