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.

Weird or what? USART problem

Status
Not open for further replies.
thats the line which I added specially for that and RA7 is never set, so something different happens.
 
1)org 0 ;add this why? it doesn't actually change anything...

"org" is an assembler directive that tells the assembler to place the line or lines of code that follows it at a specific address location in program ROM.

When dealing with code that uses an ISR, the start of the ISR OR the jump instruction that jumps the program counter to the ISR (i.e. something like "goto ISR") must reside at program ROM address 0x04 specifically. This is because that is the address that the program counter jumps to when an interrupt is triggered. This is how the uC knows what code segment to go to when an interrupt is triggered.

Program ROM address 0x00 is the "reset vector". This is the address in program ROM that the program counter starts at upon initial power up as well as after a reset condition.

If you just start typing code, your first instruction will automatically reside in address 0x00 and each line of code after that resides in the addresses which follow it. Without the ORG statements, your code will overwrite address 0x04, and the program counter will never find your ISR code when an interrupt is triggered. It will jump to address 0x04, and start executing whatever code resides there and continue on from there, which will make your code become a rogue program.

When you do a -

Code:
		org		0x00
		goto		START

		org		0x04
		goto		ISR

This puts the jump instruction "goto START" at address 0x00, which jumps the program counter to the start of your main code upon initial power up and/or reset, and the jump instruction "goto ISR" at address 0x04, which jumps the program counter to your ISR code upon triggering of an interrupt. This way when the program counter starts at address 0x00, it immediately jumps to the start of your main code. Then when an interrupt triggers the program counter to jump to address 0x04, it will see the line "goto ISR" (or whatever you happened to label your ISR code as) and immediately jump to the start of your ISR code.

Most books that speak of the "org" directive state that it means "origin". However, I find it easier to think of it as "organize" as it allows you to "organize" your code by placing a specific line of code at a specific program ROM address location.

2)sorry for my bad English, I can't understand what "straggle a page boundary" means, can you explain with simpler words?

It's actually "straddle" a page boundary. Program ROM is organized into "pages", and each "page" of program ROM is 2K bytes deep. Each page is divided up into 8 256 byte sections. If you have a look up table that occupies a section of a page that overlaps a 256 byte boundary, you must increment the value of PCLATH when accessing table lines that start after that 256 byte boundary or it will jump to the wrong line of code upon a table call, which turns your code into a rogue program.
 
Last edited:
Thanks Jon, and what about the problem?
 
can any1 give me his skype address to share my screen and show everything? (debugging with ISIS and mplab) and talk with more convenient way
 
All i want is to know: If String is being sent from PC and PIC goes in other delay, two level FIFO buffers are filled and if another char comes while buffer is full, something happens which I want to know.... 3 pages and noone has answered. P.S. see my file!!!! no overrun error flag is set!!!
 
All i want is to know: If String is being sent from PC and PIC goes in other delay, two level FIFO buffers are filled and if another char comes while buffer is full, something happens which I want to know.... 3 pages and noone has answered. P.S. see my file!!!! no overrun error flag is set!!!

If both levels of RCREG are still full by the time the receive shift register shifts in the last bit of a 3rd received byte, a buffer overrun error occurs, which should set the overrun error flag (RCSTA,OERR). Clearing the continuous receive bit in the RCSTA register (RCSTA,CREN), reading the RCREG register twice, then setting the continuous receive bit will clear the overrun error.
 
Last edited:
Try this code -

Code:
   ; W = 196 (32)
   ; S = 160 (64)
   ; A = 128 (96)
   ; D = 96 (128)
   ; N = 64 (160)

   
		list		P=16F628A
		include		<P16F628A.INC>		;Include header file
		radix		dec

		__config	_CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
		errorlevel	-302

;disabled features -
;Code Protection (CP)
;Data Code Protection (CPD)
;Low Voltage Programming (LVP)
;Brown Out Detection (BODEN)
;External Master Clear (MCLRE)
;Watchdog Timer (WDT)

;enabled features -
;Power Up Timer (PWRTE)
;Internal Oscillator


;definitions table

#define		K_win		PORTA,4
#define		K_ukan		PORTA,3
#define		K_marjvniv	PORTA,2
#define		K_marcxniv	PORTA,1 
#define		K_turbo		PORTA,0

;general purpose RAM location table

		cblock		0x20
				W_TEMP
				STATUS_TEMP
 				T1
    				T2
  				T3
    		 		T4
    		 		T5
     		 		WRKNG
     		 		TURBOO
   		endc

;port initialization

 	  	org		0x00
 	  	goto		Start

 	  	org		0x04
 	  	goto		ISR
 
Start		nop
		banksel		PCON		;set internal oscillator to 4MHz
		bsf		PCON,OSCF


 	 	movlw 		b'00000110'       ;RB1(RX)=1, RB2(TX)=1, others are 0 
  	 	movwf 		TRISB

  		movlw 		b'00011111'
 		movwf 		TRISA

;disable on chip comparator

		banksel		CMCON
		movlw		7 
  	 	movwf 		CMCON          

;enable peripheral interrupts		
	   
  	 	movlw		b'11000000'
 	 	movwf		INTCON  

;enable USART receive interrupt

		movlw		b'00100000'
		movwf		PIE1

; Boot Baud Rate = 9600, No Parity, 1 Stop Bit 
; 
		movlw		0x19              ; 0x19=9600 bps (0x0C=19200 bps) 
		movwf		SPBRG 
		movlw		b'00100100'       ; brgh = 64x, transmit enabled
		banksel		TXSTA		  ; switch to bank 1
   	 	movwf		TXSTA             ; enable Async Transmission, set brgh
   	 	banksel		RCSTA		  ; switch to bank 0
   	 	movlw		b'10010000'       ; enable Async Reception 
  	 	movwf		RCSTA 


		call		message

loop 		movlw		3
   		btfss		K_win
   		addwf		PCL,F
   		call		Dacda_
   		movlw		32
   		call		Action

		movlw		3
		btfss		K_ukan
		addwf		PCL,F
		call		Dacda_
		movlw		64
		call		Action

		movlw		3
		btfss		K_marjvniv
		addwf		PCL,F
		movlw 		96
		call 		Action
   		call 		Dacda__

   		movlw 		3
   		btfss 		K_marcxniv
   		addwf		PCL,F
   		movlw 		128
   		call 		Action
   		call 		Dacda__

   		movlw 		3
  		btfss 		K_turbo
   		addwf 		PCL,F
  		movlw 		160
   		call 		Action
   		call		Dacda__

   		goto loop 

; ------------------------------------------------------------- 
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING 
; ------------------------------------------------------------- 
; 
send		movwf		TXREG             ; send data in W
		banksel		TXSTA
		btfss		TXSTA,TRMT        ; (1) transmission is complete if hi 
   		goto		$-1
		banksel		PORTA
		return 


ISR		movwf		W_TEMP			;back up current state of W and status registers
		swapf		STATUS,W
		movwf		STATUS_TEMP 		 

		movfw		RCREG			;move received data into W

		call send
		movwf 		T1

   		sublw 		a'w'
   		movlw 2
   		btfss 		STATUS, Z
   		addwf 		PCL, f
   		movlw 		32
   		call	 	Action


   		movfw 		T1
   		sublw 		a's'
   		movlw 		2
   		btfss 		STATUS, Z
   		addwf 		PCL, f
   		movlw 		64
   		call 		Action

   		movfw		T1
   		sublw 		a'a'
   		movlw 		2
   		btfss 		STATUS, Z
   		addwf 		PCL, f
   		movlw 		96
   		call 		Action

   		movfw		 T1
   		sublw 		a'd'
   		movlw 		2
   		btfss 		STATUS, Z
   		addwf 		PCL, f
   		movlw 		128
   		call 		Action

   		movfw 		T1
   		sublw		a'n'
   		movlw 		2
   		btfss 		STATUS, Z
   		addwf 		PCL, f
   		movlw 		160
   		call 		Action

  		swapf		STATUS_TEMP,W		;restore status and w registers to "pre-interrupt" state
		movwf		STATUS
		movfw		W_TEMP
		retfie






Action   	iorwf 		PORTB,F
   		call 		Dacda
   		call 		Dacda
   		call 		Dacda
  		call		Dacda   ;<<<<<<<--------------------------------------------- THIS!!!!!!!!!!
   		movlw 		b'00011111'
   		andwf 		PORTB,F
   		return


Del1 		movlw 		30
   		movwf 		T2
   		decfsz 		T2, f
   		goto 		$-1
   		return



message 	movlw 		a'J'
   		call 		send
   		movlw 		a'a'
   		call 		send
   		movlw 		a'K'
   		call 		send
   		movlw		a'o'
   		call 		send
   		movlw 		a' '
   		call 		send
   		movlw 		a'V'
   		call 		send
   		movlw 		a'0'
   		call 		send
   		movlw 		a'.'
   		call 		send
   		movlw 		a'1'
   		call 		send
   		movlw 		0x0D
   		call 		send

   		return	


Dacda_ 		call 		Dacda
   		call 		Dacda
   		call 		Dacda
   		call 		Dacda
   		return

Dacda__ 	movlw 		50
   		movwf 		TURBOO
XAX   		decfsz 		TURBOO,F
   		call 		Dacda_
   		decfsz 		TURBOO,F
   		goto 		XAX
   		return

Dacda 		movlw 		200
   		movwf 		T3
   		decfsz 		T3,F
   		call 		Del1
   		decfsz 		T3,F
   		goto 		$-3
   		return




        END
 
Last edited:
Thanks jon, I feel ashamed becouse of the stupid error. I disturbed the whole forum :S. The problem was that I was simulating the wrong file in Proteus and that's why I could not solve such stupid error. thank you very much and I promise that I will be more attentive next time before posting : ))
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top