Docstoc

uart-assembler

Document Sample
uart-assembler Powered By Docstoc
					                                                            Electronic Department EEPIS-ITS
                                                                   Embedded Research Group




UART with vmlab 3.12




 Copyright © by Akhmad hendriawan
 hendri@eepis-its.edu
 Seluruh dokumen ini dapat digunakan, dimodifikasi dan disebarkan
 secara bebas untuk tujuan bukan komersial (nonprofit), dengan syarat
 tidak menghapus atau merubah atribut penulis dan pernyataan
 copyright   yang     disertakan   dalam   setiap   dokumen.   Tidak
 diperbolehkan melakukan penulisan ulang, kecuali mendapatkan ijin
 terlebih dahulu dari penulis
                                                                   Electronic Department EEPIS-ITS
                                                                          Embedded Research Group



1. Run vmlab
2. select project from main menu then select new project.




3. Give name of project, Select atmega8, select GNU C compiler. Make sure GCC path is correct
                                                       Electronic Department EEPIS-ITS
                                                              Embedded Research Group

  4. change listing program with this following line
.include "C:\VMLAB\include\m8def.inc"
.equ baudrate=0x0019
.def temp=r16
.def data=r17
.org 0x0000
rjmp reset

;*******************
; rx uart
;*******************
rx_uart:
; Wait for data to be received
sbis UCSRA, RXC
rjmp rx_uart
; Get and return received data from buffer
in data, UDR
ret

;*******************
; tx uart
;*******************
tx_uart:
; Wait for empty transmit buffer
sbis UCSRA,UDRE
rjmp tx_uart
; Put data into buffer, sends the data
out UDR,data
ret


;*******************
;setup uart
;*******************
setup_uart:
; Set baud rate
ldi temp,low(baudrate)
out UBRRL, temp
ldi temp,high(baudrate)
out UBRRH, temp

; Enable Receiver and Transmitter
ldi temp, (1<<RXEN)|(1<<TXEN)
out UCSRB,temp
; Set frame format: 8data, 1stop bit
                                                             Electronic Department EEPIS-ITS
                                                                    Embedded Research Group


ldi temp, (1<<URSEL)|(3<<UCSZ0)
out UCSRC,temp
ret

;********************
; main program here
;********************
reset:
;Location of Stackpointer
ldi temp, low(RAMEND)
out SPL, temp
ldi temp, high(RAMEND)
out SPH, temp

rcall setup_uart

loop:
rcall rx_uart
rcall tx_uart
rjmp loop

  5. Add terminal emulator in project file
xterm TTY(9600 8) PD0 PD1

  6. Change frequency simulation to 4Mhz in file project. Look red line
; Following lines are optional; if not included
; exactly these values are taken by default
; ------------------------------------------------------------
.POWER VDD=5 VSS=0 ; Power nodes
.CLOCK 4meg             ; Micro clock
.STORE 250m             ; Trace (micro+signals) storage time
                                                                    Electronic Department EEPIS-ITS
                                                                           Embedded Research Group

7. Select project from main menu then select build (F9)




8. if error try to add newline in end of project file

9. if success display like here




10. select view from main menu and select control panel (Alt+shift+C)




11. Select go toolbar
                                                 Electronic Department EEPIS-ITS
                                                        Embedded Research Group




   12. the result should be like the following




Last revised on october 22, 2007
email: hendri@eepis-its.edu

reference:
    1. Atmel AVR datasheet
    2. www.avrfreaks.net
    3. www.avrtutor.com
    4. www.xdesignlabs.com
    5. Atmel AvrStudio

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:89
posted:2/22/2010
language:Indonesian
pages:6