Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

chek code assembler

Status
Not open for further replies.

gimmy

New Member
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
 
Your code looks fine except that the interrupt vector should be at 0004 not 0008 (even though you don't use them) . Your code is a little unreadable due to the way the BB has formated it. Could you repost (or edit) it and use the Code tag then it will be much more readable.

edit, I just had another look and I think you need to start again. You are setting up the hardware USART and then attempting to do software serial using the hardware registers. Your code falls through to your message send routine which then returns to nowhere. I think that you would gain a lot by working your way through Nigels tutorial.

HTH

Mike.
 
question

hey i understand my problem but i don't understand how i can resolve it.
the problem is could someone tell me how i can generate a routine that allows me to send a address?
thanks a lot
 
Re: question

gimmy said:
hey i understand my problem but i don't understand how i can resolve it.
the problem is could someone tell me how i can generate a routine that allows me to send a address?
thanks a lot

What do you mean by 'send an address'?, it's pretty meaningless!.

If you're talking RS232 you sent 8 bit values, if you want to send a 16 bit value, you simply send it as two 8 bit ones.
 
help

sorry you are right. the address is the address of remote device to send then the byte through bluetooth. i have
pic>eb500 ....bluetooth.....eb500>pic
i need to set the address like 00:00:00:00:00:00 in assembler.
thanks i hope that now is more clear.
thanks a lot
 
Re: help

gimmy said:
sorry you are right. the address is the address of remote device to send then the byte through bluetooth. i have
pic>eb500 ....bluetooth.....eb500>pic
i need to set the address like 00:00:00:00:00:00 in assembler.
thanks i hope that now is more clear.
thanks a lot

It's only an ASCII string, just send it one byte at a time.
 
yes i know this but i don't know i can write it,could you help me with an examples, because i don't understand if i send for example 0 then when i write the other 0 there is a problem of overwrite, right? so i can send the address. could you give me an example, please?
thanks
 
gimmy said:
yes i know this but i don't know i can write it,could you help me with an examples, because i don't understand if i send for example 0 then when i write the other 0 there is a problem of overwrite, right? so i can send the address. could you give me an example, please?
thanks

If you check my tutorials, some of those send strings via RS232, there's no 'overwrite problem', as long as the receiver can process the bytes fast enough. If not, simply add delays between the transmitted bytes, but it shouldn't be required.

This is a simple (crude!) method of sending a 'string' "123".
Code:
movlw '1'
call RS232_Send
movlw '2'
call RS232_Send
movlw '3'
call RS232_Send

Where the subroutine 'RS232_Send' transmits the byte in W via the serial port.
 
thanks guy, but i don't use a rs232, i'm using a uart communication and i can connect the pic to eb500 directly.
but for you rs232_send is...?
could you show me some details more, please ?only to understand better what i can do.
thanks
 
gimmy said:
thanks guy, but i don't use a rs232, i'm using a uart communication and i can connect the pic to eb500 directly.
but for you rs232_send is...?
could you show me some details more, please ?only to understand better what i can do.
thanks

I only called it 'RS232_Send' as an example, you can call it 'Serial_Send' or anything you want.

Check my tutorials for examples of both software and hardware serial routines - software has the advantages that you can use any pin you want, and you can invert it's polarity if you need to - the hardware UART is fixed polarity, designed to feed a MAX232 chip, and uses specific fixed pins.
 
As Nigel told you, if your system if fast enough you won't have problems with the reception of the address.
I did once a rs422 serial comm with two external devices and one master that send and receive data from the other two.

You need a master and the other is a slave. Then the master will send the address+data and the slave will receive all data by polling or by interruption, you decide the slave system has to compare all received data, if the copmpleate address is got, then valid data to receive, if not just follow waiting for the valid address, until the slave system is waked-up by the master. then go to the appropriate routine to receive valid data

it is like our names, you understand until someone said you name, then you pay attention.
the system has to check the address if the address is valid the it handles the data, I think it must be complex because you need to avoid lost of data, your slave system must tell the master system I am ready to receive, if not the fisrt data will be lost.

but try, then you will be familiarized to make you own RF protocol
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top