打印

LED交替亮

[复制链接]
2352|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
LED, TE, se, ST, pi
本帖最后由 zhangziye0505 于 2013-4-7 09:25 编辑

救命···
现在有Msp430g2553 Lauchpad  用code composer studio version5(CCSv5)
写个模拟交通信号灯的代码 绿黄红的交替亮 红绿亮10秒 黄亮5秒(好像没有黄灯 可以用红绿一起亮代表黄灯)
下面那些笑脸的表情都是P 不知道为什么会变成表情
有个可以让led闪的code 和一个 interrupt的code
LED Blink的code如下:

;*******************************************************************************
            .cdecls C,LIST,"msp430g2553.h"  ; Include device header file

            .text                           ; Place program in ROM (Flash)
            .global _main                   ; set entry point
INIT_STACK: .set    0x400                   ;0x400 = 0x03FE+2, 0x03FE = RAM BOTTOM

_main:
             mov.w   #INIT_STACK,SP         ; initialize stack pointer  11
StopWDT:     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT (Watch Dog Timer) 12
SetupP1:     bis.b   #41h, &P1DIR           ; Set Pin P1.0 and Pin P1.6 as output pins (P1.0 and
                                            ;P1.6 connected to LEDs)
                                            ; immediate mode, absolute mode
                                            ; 41 hex = 001000001 binary

Mainloop:   xor.b   #41h, &P1OUT           ; Toggle P1.0 and P1.6
                                            ; immediate mode, absolute mode
                                            ; 41 hex = 01000001 binary

Wait:       mov.w   #65535, R15            ; Put delay in R15
                                            ; immediate mode, absolute mode

L1:         dec.w   R15                     ; Decrement R15
            jnz     L1
           ; xor.b   #40h, &P1OUT                    ; Delay over?
            jmp     Mainloop                ; Again


;Interrupt Vectors

           .sect   ".reset"                ; MSP430 RESET Vector
           .short  _main
           .end
这个是Interrupt Button

;------------------------------------------------------------------------------
        .cdecls C,LIST,"msp430g2553.h"  ; cdecls tells assembler to allow
                                        ; the c header file

;------------------------------------------------------------------------------
        .text                           ; program start
        .global _main                                    ; define entry point

INIT_STACK:        .set        0x400 ;0x400 = 0x03FE+2, 0x03FE = RAM BOTTOM
;------------------------------------------------------------------------------
;   Main Code
;------------------------------------------------------------------------------
_main:
                mov.w   #INIT_STACK,SP                           ; initialize stack pointer
        mov.w   #WDTPW+WDTHOLD,&WDTCTL          ; stop watchdog timer

                clr.b        &P1DIR                                                ; set all pins on Port1 for input
                clr.b        &P1IFG                                                ; clear the interupt flag for all pins on Port1
                clr.b        &P1OUT                                                ; clear output buffer for all pins on Port1
                bis.b        #BIT6, &P1DIR                                ; set pin6 of prot1 (pin 1.6) as output pin (LED)
                bis.b        #BIT3, &P1OUT                                ; set pin3 of port1 (pin 1.3, pushbutton) to pullup
                bis.b        #BIT3, &P1REN                                ; set pullup resistor at pin 3 of port 1 (pin 1.3)
                bis.b        #BIT3, &P1IES                                ; interrupt on falling edge signal on pin 1.3
                bis.b        #BIT3, &P1IE                                ; enable interrupt on pin3 of port1 (pin 1.3)

Sleep        bis.w        #GIE|CPUOFF|SCG1|SCG0,SR        ; Enter LPM3  (Low Power Mode 3), ENABLE INTERRUPTS
                                                                                        ; MCLK, SMCLK  off

                mov.w        #6,R14                                        ; R14 counts how many times the big delay loop is executed
Next        xor.b   #BIT6,&P1OUT            ; Toggle P1.6 (led)
        mov.w   #65535,R15              ; R15 is the counter for the big delay loop
L1      dec.w   R15                     ; Decrement big delay loop counter
        jnz     L1                      ; Delay over?
        dec.w        R14                                                ; yes, dealy over, decrement R14 counter
        jnz                Next                                        ; go to big delay loop again

                jmp                  Sleep                                        ; go to sleep again

PORT1_ISR:

                bic.w        #CPUOFF|SCG1|SCG0,0(SP)        ; CPU awake on return from ISR

                clr.b   &P1IFG                        ; multi sourced interrupt, therefore you must clear the interrupt flag

                reti                                        ; return from interrupt

;------------------------------------------------------------------------------
;   Interrupt Vectors
;------------------------------------------------------------------------------
         .sect        ".int02"
                 .short        PORT1_ISR

         .sect   ".reset"                ; MSP430 RESET Vector
         .short  _main
                 .end

相关帖子

沙发
huangxz| | 2013-4-7 22:27 | 只看该作者
楼主可以用高级模式,然后用插入代码

这样就不会出现表情符号了。如上图的圈里面

使用特权

评论回复
板凳
mmbs| | 2013-4-7 22:39 | 只看该作者
汇编表示看不懂了。

使用特权

评论回复
地板
mmbs| | 2013-4-7 22:40 | 只看该作者
楼主很牛X呀

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

3

帖子

1

粉丝