Created
October 16, 2012 00:15
-
-
Save axpence/3896515 to your computer and use it in GitHub Desktop.
Working switch AND morse code!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .title "morse.asm" | |
| ;******************************************************************************* | |
| ; Project: morse.asm | |
| ; Author: Student Code | |
| ; | |
| ; Description: Outputs a message in Morse Code using a LED and a transducer | |
| ; (speaker). The watchdog is configured as an interval timer. | |
| ; The watchdog interrupt service routine (ISR) toggles the green | |
| ; LED every second and pulse width modulates (PWM) the speaker | |
| ; such that a tone is produced. | |
| ; | |
| ; Revisions: | |
| ; | |
| ; RBX430-1 eZ430 Rev C | |
| ; OPTION A OPTION B | |
| ; .------------. .------------. | |
| ; SW1-->|P1.0^ P3.0|-->LCD_A0 (RED) LED<--|P1.0 P3.0|-->LCD_RST | |
| ; SW2-->|P1.1^ P3.1|<->SDA (GREEN) LED<--|P1.1 P3.1|<->SDA | |
| ; SW3-->|P1.2^ P3.2|-->SCL NC-->|P1.2 P3.2|-->SCL | |
| ; SW4-->|P1.3^ P3.3|-->LCD_RW NC-->|P1.3 P3.3|-->LED_3 (Y) | |
| ; INT1-->|P1.4 P3.4|-->LED_5 (GREEN) NC-->|P1.4 P3.4|<--NC | |
| ; INTA-->|P1.5 P3.5|<--RX NC-->|P1.5 P3.5|<--NC | |
| ; SVO1<--|P1.6 P3.6|<--RPOT NC-->|P1.6 P3.6|<--NC | |
| ; SVO2<--|P1.7 P3.7|<--LPOT NC-->|P1.7 P3.7|<--NC | |
| ; | | | | | |
| ; LCD_D0<->|P2.0 P4.0|-->LED_1 (G) SW_1-->|P2.0^ P4.0|<--NC | |
| ; LCD_D1<->|P2.1 P4.1|-->LED_2 (O) SW_2-->|P2.1^ P4.1|<--NC | |
| ; LCD_D2<->|P2.2 P4.2|-->LED_3 (Y) SW_3-->|P2.2^ P4.2|<--NC | |
| ; LCD_D3<->|P2.3 P4.3|-->LED_4 (R) SW_4-->|P2.3^ P4.3|<--RPOT | |
| ; LCD_D4<->|P2.4 P4.4|-->LCD_BL LCD_BL<--|P2.4 P4.4|<--LPOT | |
| ; LCD_D5<->|P2.5 P4.5|-->SPEAKER NC-->|P2.5 P4.5|-->SPEAKER | |
| ; LCD_D6<->|P2.6 P4.6|-->LED_6 (RED) (G) LED_1<--|P2.6 P4.6|-->LED_4 (R) | |
| ; LCD_D7<->|P2.7 P4.7|-->LCD_E (O) LED_2<--|P2.7 P4.7|<--NC | |
| ; .------------. .------------. | |
| ; | |
| ;******************************************************************************* | |
| .cdecls C,LIST,"msp430.h" ; include c header | |
| ;------------------------------------------------------------------------------ | |
| ; System equates | |
| myCLOCK .equ 1200000 ; 1.2 Mhz clock | |
| WDT_CTL .equ WDT_MDLY_0_5 ; WD configuration (Timer, SMCLK, 0.5 ms) | |
| WDT_CPI .equ 500 ; WDT Clocks Per Interrupt (@1 Mhz) | |
| WDT_IPS .equ myCLOCK/WDT_CPI ; WDT Interrupts Per Second | |
| STACK .equ 0x0600 ; top of stack | |
| DEBOUNCE .equ 5 | |
| ;------------------------------------------------------------------------------ | |
| ; External references | |
| .ref numbers ; codes for 0-9 IMPORTS STUFF FROM MORSE_CODES.ASM | |
| .ref letters ; codes for A-Z | |
| letterTb: .set letters-'A'*2 | |
| numberTb: .set numbers-'0'*2 | |
| ; numbers--->N0$--->DASH,DASH,DASH,DASH,DASH,END ; 0 | |
| ; N1$--->DOT,DASH,DASH,DASH,DASH,END ; 1 | |
| ; ... | |
| ; N9$--->DASH,DASH,DASH,DASH,DOT,END ; 9 | |
| ; | |
| ; letters--->A$---->DOT,DASH,END ; A | |
| ; B$---->DASH,DOT,DOT,DOT,END ; B | |
| ; ... | |
| ; Z$---->DASH,DASH,DOT,DOT,END ; Z | |
| ; Morse code is composed of dashes and dots, or phonetically, "dits" and "dahs". | |
| ; There is no symbol for a space in Morse, though there are rules when writing them. | |
| ; 1. One dash is equal to three dots | |
| ; 2. The space between parts of the letter is equal to one dot | |
| ; 3. The space between two letters is equal to three dots | |
| ; 4. The space between two words is equal to seven dots. | |
| ; 5 WPM = 60 sec / (5 * 50) elements = 240 milliseconds per element. | |
| ; element = (WDT_IPS * 6 / WPM) / 5 | |
| ; Morse Code equates | |
| ELEMENT .equ WDT_IPS*204/1000 ;LENGTH OF A DOT / DASH / NOTHING? SPACE=1 ELEMENT... | |
| Big_Number .equ 2000 | |
| DOT .equ 1 | |
| DASH .equ 2 | |
| SPACE .equ ELEMENT*7 ;end space for when the program ends. | |
| ;------------------------------------------------------------------------------ | |
| ; Global variables ; RAM section | |
| .bss beep_cnt,2 ; beeper flag .BSS IS A MEMORY LOCATION | |
| .bss delay_cnt,2 ; delay flag | |
| .bss led_sec_1a,2 ; variable for big number | |
| .bss debounce_cnt,2 ; debounce count | |
| .bss beep_on,2 ;is beep on? | |
| ;------------------------------------------------------------------------------ | |
| ; Program section | |
| .text ; program section | |
| message: .string "HELLO CS 124 WORLD " ; PARIS message | |
| .byte 0 | |
| .align 2 ; align on word boundary MAKES MEMORY ORGANIZED BY 2 BYTES.. | |
| RESET: mov.w #STACK,SP ; initialize stack pointer | |
| mov.w #WDT_CTL,&WDTCTL ; set WD timer interval HOW LONG WE SAY THE WATCHDOG WAITS BEFORE INTURRUPTING | |
| mov.b #WDTIE,&IE1 ; enable WDT interrupt ALLOWS wd TO INTURRUPT | |
| bis.b #0x20,&P4DIR ; set P4.5 as output (speaker) NEED TO SET LEDS AS OUTPUTS AS WELL | |
| clr.w beep_cnt ; clear counters MAKE ALL 0'S JUST IN CASE... | |
| clr.w delay_cnt | |
| clr.w led_sec_1a | |
| clr.w debounce_cnt | |
| clr.w beep_on | |
| call #init_switches | |
| bis.b #0x40,&P4DIR ;Set P4.6 as output ME EDITZ | |
| bis.b #0x10,&P3DIR ;Set P3.4 as output ME EDITZ | |
| clr.w delay_cnt | |
| bis.w #GIE,SR ; enable interrupts SAYS PROGRAM IS ALLOWED FOR INTURRUPTS, SAVED ON STATUS REGISTER. IF THIS FLAG IS NOT SET, INTURRUPT WILL NOT BE ACKNOWLEDGED | |
| mov.w #Big_Number, led_sec_1a ;initialize value | |
| ; LETZ TRY AND DO THE DANCEWY | |
| loop: mov.w #message, r4 | |
| loop02: mov.b @r4+,r5 ; get character | |
| cmp.b #0x00,r5 ;IS NULL? | |
| jeq null_loop | |
| cmp #0x20,r5 ;IS SPACE? | |
| jeq space_loop | |
| cmp.b #0x41, r5 ;anything greater than 41 = letter cmpb.#0x41,r6 | |
| jge letter_loop | |
| jmp number_loop ;less than 41 = NUMBER | |
| add.w r5,r5 ; make word index, DOUBLING AND MAKING MEMORY LOCATION | |
| mov.w letterTb(r5),r5 ; get pointer to letter codes WILL MOVE DOT / DASH SEQUENCE INTO R5 | |
| null_loop: | |
| ;delay? | |
| call #do_space ;since at the end the delay is the same as a space loop. | |
| jmp loop ;start over since NULL | |
| space_loop: | |
| call #do_space | |
| jmp loop02 | |
| letter_loop: | |
| ;see which letter it is | |
| ;call out dashes and dots. | |
| add.w r5,r5 ; make word index | |
| mov.w letterTb(r5),r5 ; get pointer to letter codes | |
| letter_number_1a: | |
| mov.b @r5+,r6 ; get DOT, DASH, or END | |
| cmp.b #DOT,r6 ; dot? | |
| jeq do_dot | |
| cmp.b #DASH,r6 | |
| jeq do_dash ;ELSE JUMP TO DO_DASH | |
| cmp.b #0x00,r6 | |
| jne letter_number_1a | |
| ;when zero call small space... | |
| mov.w #ELEMENT*3,r15 | |
| call #delay | |
| jmp loop02 ;return.. | |
| number_loop: | |
| ;see what number it is | |
| ;call out dashes and dots | |
| add.w r5,r5 ; make word index | |
| mov.w numberTb(r5),r5 ; get pointer to letter codes | |
| jmp letter_number_1a | |
| do_space: mov.w #ELEMENT*7,r15 ; output space | |
| call #delay ; delay | |
| ret | |
| ;7 ELEMENTS = END OF MESSAGE | |
| do_dot: mov.w #ELEMENT,r15 ; output DOT | |
| call #beep | |
| mov.w #ELEMENT,r15 ; delay 1 element | |
| call #delay | |
| jmp letter_number_1a | |
| do_dash: mov.w #ELEMENT*3,r15 ; output DASH | |
| call #beep | |
| mov.w #ELEMENT,r15 ; delay 1 element | |
| call #delay | |
| jmp letter_number_1a | |
| ; beep r15 ticks of the watchdog timer | |
| beep: mov.w r15,beep_cnt ; start beep | |
| bis.b #0x40,&P4OUT ; start red led on with beep | |
| beep02: tst.w beep_cnt ; beep finished? ENDLESS LOOP... WAITS FOR WATCHDOG ISR TO DEC BEEP_CNT | |
| jne beep02 ; n | |
| bic.b #0x40,&P4OUT ; stop red led when beep is finished | |
| ret ; y | |
| ; delay r15 ticks of the watchdog timer | |
| delay: mov.w r15,delay_cnt ; start delay | |
| delay02: tst.w delay_cnt ; delay done? | |
| jne delay02 ; n | |
| ret ; y | |
| init_switches: | |
| bic.b #0x0f,&P1SEL ; RBX430-1 push buttons | |
| bic.b #0x0f,&P1DIR ; Configure P1.0-3 as Inputs | |
| bis.b #0x0f,&P1OUT ; pull-ups | |
| bis.b #0x0f,&P1IES ; h to l | |
| bis.b #0x0f,&P1REN ; enable pull-ups | |
| bis.b #0x0f,&P1IE ; enable switch interrupts | |
| ret | |
| ;------------------------------------------------------------------------------ | |
| ; Watchdog Timer interrupt service routine | |
| ; | |
| WDT_ISR: tst.w beep_cnt ; beep on? wether beeper is set to on or off | |
| jeq WDT_GREEN ; n IS BEEP_CNT A ZERO? | |
| dec.w beep_cnt ; y, decrement count | |
| ;test to see if beep_on is a 1 | |
| tst.w beep_on | |
| jeq WDT_GREEN | |
| xor.b #0x20,&P4OUT ; beep using 50% PWM FLIP SPEAKER | |
| ;ONE SECOND ON AND OFF GREEN LED | |
| WDT_GREEN: dec.w led_sec_1a ;decrement value to blink one second | |
| jnz WDT_02 ;when not zero continue to WDT_02 | |
| xor.w #0x10,&P3OUT ;toggle GREEN led | |
| mov.w #Big_Number, led_sec_1a ;put big number back into value to be decremented. | |
| WDT_02: tst.w delay_cnt ; delay? LIGHT???? | |
| jeq WDT_10 ; n | |
| dec.w delay_cnt ; y, decrement count EDIT HERE TO TURN LIGHT ON? | |
| ;---------asdf--------------------------------------------------------------------- | |
| WDT_10: | |
| tst.w debounce_cnt ; debouncing? | |
| jeq WDT_30 ; n JNE? | |
| ; debounce switches & process | |
| dec.w debounce_cnt ; y, decrement count, done? | |
| jne WDT_30 ; n | |
| push r15 ; y | |
| mov.b &P1IN,r15 ; read switches | |
| and.b #0x0f,r15 ;GET RID OF LAST BITS | |
| xor.b #0x0f,r15 ; any switches? | |
| jeq WDT_20 ; n EXTRA CREDIT CHECK FOR OTHER BUTTONS AND JUMP ACCORDINGLY | |
| ;cmp.b #0x01,r15 | |
| ;jne WDT_20 | |
| ;WHAT DO WE WANT TO HAPPEN WHEN 0001 IS PRESSED? | |
| xor.b #0x01,beep_on ; set P4.5 as output (speaker) NEED TO SET LEDS AS OUTPUTS AS WELL | |
| ; process switch inputs (r15 = switches) | |
| WDT_20: pop r15 | |
| jmp WDT_30 | |
| WDT_30: reti ; return from interrupt | |
| ;------asdf------------------------------------------------------------------------ | |
| ;------------------------------------------------------------------------------ | |
| P1_ISR: bic.b #0x0f,&P1IFG ; acknowledge (put hands down) | |
| mov.w #DEBOUNCE,debounce_cnt ; reset debounce count | |
| reti | |
| ;------------------------------------------------------------------------------ | |
| ;------------------------------------------------------------------------------ | |
| ; Interrupt Vectors | |
| ;------------------------------------------------------------------------------ | |
| .sect ".int10" ; Watchdog Vector | |
| .word WDT_ISR ; Watchdog ISR | |
| .sect ".reset" ; PUC Vector | |
| .word RESET ; RESET ISR | |
| .sect ".int02" | |
| .word P1_ISR | |
| .end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment