Check my Assembly code for UART communication between pic16f73 and eb500

Status
Not open for further replies.

gimmy

Newbie level 2
Joined
May 3, 2005
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,329
sorry guy but i missed myself, i don't know why my code doesn't work, could someone help me e chek it,please?
title "PIC16F73"
list p=16f73,f=inhx32
#include <p16f73.inc>


MSGPTR EQU 0x26 ;General purpose register
BITS EQU 0x27 ; General purpose register
CNTMSEC EQU 0x28 ; General purpose register
ZEROBIT EQU 0x02 ;Zero bit of Status Reg
DELAY1_VAL1 EQU 0x21
DELAY1_VAL1_TEMP EQU 0x22
DELAY2_VAL1 EQU 0x23
DELAY2_VAL1_TEMP EQU 0x24
TMR0_TEMP EQU 0x25 ;Used for storing TMR0 during interrupt
W_TEMP EQU 0x29 ;Used for storing W during interrupt
SPBRG_VAL EQU 0x30 ;set baud rate 9600 for 4Mhz clocK
PAUSE_DELAY EQU 0x31
CBLOCK 0x020
Flags ;byte to store indicator flags
ENDC

ORG 0x00 ;reset vector
GOTO Start
ORG 0x08 ;Origin for the external RA0/INT


DELAY1 MOVLW 0xB2 ;No. of outer loops is 0xFF-val
MOVWF DELAY1_VAL1 ;
LOOP2 MOVLW 0x01 ;No. of inner loops is 0xFF-val
MOVWF TMR0
BANKSEL OPTION_REG ;
MOVLW B'11000111' ;set prescaler to 256
MOVWF OPTION_REG ;
BANKSEL PORTA
LOOP1
MOVF TMR0,0 ;Affects the Z bit of STATUS
BTFSS STATUS,ZEROBIT ;See if Z bit is set
GOTO LOOP1 ;No, check again
INCF DELAY1_VAL1,1 ;yes, inc DELAY1_VAL1 Affects Z bit
BTFSS STATUS,ZEROBIT ;used to see if DELAY1_VAL1 is zero
GOTO LOOP2 ;NO - start inner loop again
RETLW 0 ;YES - return from DELAY1

DELAY2 MOVLW 0xFE ;No. of outer loops is 0xFF-val
MOVWF DELAY2_VAL1 ;
LOOP4 MOVLW 0x01 ;No. of inner loops is 0xFF-val
MOVWF TMR0
MOVLW B'11000111' ;set prescaler to 256
BANKSEL OPTION_REG ;
MOVWF OPTION_REG ;
BANKSEL PORTA
LOOP3
MOVF TMR0,0 ;Affects the Z bit of STATUS
BTFSS STATUS,ZEROBIT ;See if Z bit is set
GOTO LOOP3 ;No, check again
INCF DELAY2_VAL1,1 ;yes, inc DELAY1_VAL1 Affects Z bit
BTFSS STATUS,ZEROBIT ;used to see if DELAY1_VAL1 is zero
GOTO LOOP4 ;NO - start inner loop again
RETLW 0 ;YES - return from DELAY1


Start
;Interrupt Initialisation
MOVLW B'00000000' ;Sets GIE and PORTB int.
MOVWF INTCON ;allows interrupt to be applied on PORTB<7:4>

;PORTs Initialisation
BANKSEL PORTA ;select bank of PORTA
CLRF PORTA ;
CLRF PORTB


;Port configuration
BANKSEL TRISA
MOVLW 0xFF ;Configure Port A
MOVWF TRISA ;as Inputs
MOVLW B'00000000' ;Configure Port B
MOVWF TRISB ;Outputs =0,1,2,3,4,5,6,7
MOVLW B'00000000'
MOVWF TRISC ;Configure PORTC as output
BANKSEL PORTA ;Select bank of PORTA
MOVLW B'00000000' ;All PORTC's output =0
MOVWF PORTC ;

;TX UART initialilsation
BANKSEL TRISA ;select bank 1
MOVLW 0xc0 ;set tris bits for TX and RX
MOVLW SPBRG_VAL ;set baud rate
MOVWF SPBRG
MOVLW 0x24 ;enable transmission and high baud rate
MOVWF TXSTA
BANKSEL PORTA ;select bank 0
MOVLW 0x90 ;enable serial port and reception
MOVWF RCSTA

;Set the address
OUTMSG MOVWF MSGPTR ; put 'W' into message pointer
MSGLOOP MOVF MSGPTR, W ; put the offset in 'W'
CALL MSGTXT ; returns ASCII character in 'W'
MOVWF PORTC ;
ADDLW 0 ; sets the zero flag if W = 0
BTFSC STATUS, 2 ; skip if zero bit not set
RETURN ; finished if W = 0
CALL OUTCH ; output the character
INCF MSGPTR, f ; point at next
GOTO MSGLOOP ; more characters
MSGTXT
ADDWF PCL, f ; offset added to PCL
RETLW d'1' ; 1
RETLW d'84' ; 84
RETLW 0x63 ; 'c'
RETLW 0x6F ; 'o'
RETLW 0x6E ; 'n'
RETLW 0x20 ; 'space'
RETLW 0x30 ; '0'
RETLW 0x30 ; '0'
RETLW 0x3A ; ':'
RETLW 0x30 ; '0'
RETLW 0x43 ; 'C'
RETLW 0x3A ; ':'
RETLW 0x38 ; '8'
RETLW 0x34 ; '4'
RETLW 0x3A ; ':'
RETLW 0x30 ; '0'
RETLW 0x30 ; '0'
RETLW 0x3A ; ':'
RETLW 0x30 ; '0'
RETLW 0x45 ; 'E'
RETLW 0x3A ; ':'
RETLW 0x44 ; 'D'
RETLW 0x34 ; '4'
RETLW 0x00 ; end of seding routine (acts as stop bits)

OUTCH MOVWF TXREG ; put W into transmit register
MOVLW 8 ; eight bits of data
MOVWF BITS ; count bits
;BSF PORTA, 1 ; start bit on RA1 CHEK////////////////////////
TXLOOP MOVLW 0x31 ; 49 decimal, delay time
CALL MICRO4 ; wait 49 x 4 = 196 microseconds
RRF TXREG, f ; rotate right most bit into carry
BTFSC STATUS, 0 ; if carry 0 want to set bit, ( a low )
GOTO CLRBIT ; else clear bit, ( a high )
;BSF PORTA, 1 ; +5V on pin 1 ( RA1 ) CHEK//////////////////
GOTO TESTDONE ; end of character?
CLRBIT ;BCF PORTA, 1 ; 0V on pin 1 ( RA1 ) CHEK /////////////////
NOP ; to make both options 12 micosec (ylp-"NOP")
TESTDONE DECFSZ BITS, f ; 1 less data bit, skip when zero
GOTO TXLOOP ; more bits left, delay for this one
MOVLW 0x34 ; full 208 microsec this time
CALL MICRO4 ; delay for last data bit
;BCF PORTA, 1 ; 0V, ( a high ) for stop bits CHEK/////////////////
MOVLW 0x68 ; decimal 104 delay for 2 stop bits
CALL MICRO4
RETURN
NMSEC MOVWF CNTMSEC ; W to msec count register
MSECLOOP MOVLW 0xF8 ; 8 microsec overhead
CALL MICRO4 ; 248 * 4 + 2 = 994 here
NOP ; complete delay (ylp-"NOP")
NOP ;
DECFSZ CNTMSEC, f ; decrement count, skip when zero
GOTO MSECLOOP ; loop
RETURN
MSEC1 MOVLW 0xF9 ; 4 microsec overhead
NOP ; (2 for CALL) (ylp-"NOP")
MICRO4 ADDLW 0xFF ; subtract 1 from W
BTFSS STATUS, 2 ; skip when zero
GOTO MICRO4 ; loop
RETURN

BANKSEL PORTA
BSF PORTB,4
CLRF TXREG

;A/D initialsation (A/D not used)
BANKSEL ADCON1 ;Configure A/D Ports, left Justified
MOVLW B'00000100' ;RA0 = Analog input
MOVWF ADCON1 ;Rest as Digital I/O
BANKSEL ADCON0
MOVLW B'10000000' ;Fosc/32
MOVWF ADCON0

;Switch on A/D
BANKSEL ADCON0
BSF ADCON0,0 ;Sitch on A/D
CALL DELAY2

ATOD
BSF PORTB,0
BSF ADCON0,2 ;Start A/D conversion
ATODLOOP
BTFSC ADCON0,2 ;Check to see if conversion is finished
GOTO ATODLOOP ;NO
BANKSEL ADRES
MOVF ADRES,0

;Transmit data in WREG when the transmit register is empty.
TransmitSerial:
BANKSEL PORTA ;select bank 0
BTFSS PIR1,TXIF ;check if transmitter busy
GOTO $-1 ;wait until transmitter is not busy
MOVWF TXREG
RETURN
BTFSC W,7
BTFSC W,6
CALL DELAY1
CLRF TXREG
GOTO ATOD
end

this program has to do a transmission through uart communication between pic16f73 and eb500. it takes the signal analog from porta,0 , then does a conversion in digital and send it in tx uart.

kinds regards
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…