Generate Morse Code by Mplab. Need Help!

Discussion in 'Homework Help' started by morgan, Jul 24, 2010.

  1. morgan

    Thread Starter New Member

    Jul 10, 2010
    I need to implement the software to read a four bit values from the input port and then generate the Morse code serial output to one output port. An example of a PIC program to test the Morse code generator function is shown below. The PIC program goes into an endless loop with each loop reading from the standard input and calling the main program loop. The printf function writes to the standard output. In addition, use the RAM (File Register are 0x0c to 0x4f) to store the results of computations and use the working register to pass the input and output values.

    I need to write a version of the Morse code program in PIC assembly code and test with the main program.

    ; Outline of PIC assembly program
    ; (16F84 with RC osc, watchdog timer off, power-up timer on)
    processor 16f84A
    include <>
    __config _RC_OSC & _WDT_OFF & _PWRTE_ON
    ; beginning of program code
    org 0x00 ; reset at address 0
    reset: goto init ; skip reserved program addresses
    org 0x08 ; beginning of user code
    ; At startup, all ports are inputs.
    bsf STATUS,RP0 ; switch to bank 0 memory
    clrf TRISB ; set PORTB to all outputs
    bcf STATUS,RP0 ; return to bank 1 memory
    ; here begins the main program
    movf PORTA,w ; read stdin to w reg
    call main
    goto mloop
    ; add your Morse Code here

    ; put your result into w-reg
    call printf ; output the value
    return ; main return
    printf: ; only standard library function
    movwf PORTB ; output w to stdout
    end ; end of program code

    I have several questions. First, what is the above code for? My opinion is I should write the Morse Code and add into the above code. Is it correct? How to test with the main program? Second, how to write a Morse code in Mplab? I already know how to write it in C. Please give me some instructions. I need help.
  2. Markd77

    Senior Member

    Sep 7, 2009
    The code only really sets the PIC up, the rest is up to you. It looks like you need to use a lookup table. Have a look for code that looks like:
    addwf PCL, F
    retlw ...
    retlw ...