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.

Help needed for PC-controlled Wireless Notice Board on USART

Status
Not open for further replies.

stalk3r21

New Member
Hey guys,
I'm doing a project on wireless notice board, and my codes are in assembly language
1. The wireless module is zigbee, and it's from pc to PIC,
2. The display is dot-matrix and data will be taken from EEPROM to be displayed
3. Only one way communication using USART from Zigbee to PIC6f628A
4. PIC will receive new data whenever available from ZigBee and store in EEPROM
5. The PC will be sending data through a ZigBee transmitter to the receiver.

So, currently I've got my display unit to work and everything, and can display 128 characters. All of which is pre-loaded into the EEPROM.
I'm having trouble with the communications part. How do I use USART to receive a data string and store into EEPROM one byte at a time? Plus I don't want to do the polling method.

Attached is the codings that i've written.
1. The New + new table file is working fine and i need to embed the USART part into it
2. The Usart RC file is the one I've written for serial communication with ZigBee.

The code should work as: Displaying out data from EEPROM and when new data is received, it will take it and store into EEPROM and then start displaying all over again. Please help. Thanks
 

Attachments

  • USART RC.txt
    1.3 KB · Views: 214
  • New with new table.txt
    17.9 KB · Views: 324
Hey guys,
I'm doing a project on wireless notice board, and my codes are in assembly language
1. The wireless module is zigbee, and it's from pc to PIC,
2. The display is dot-matrix and data will be taken from EEPROM to be displayed
3. Only one way communication using USART from Zigbee to PIC6f628A
4. PIC will receive new data whenever available from ZigBee and store in EEPROM
5. The PC will be sending data through a ZigBee transmitter to the receiver.

So, currently I've got my display unit to work and everything, and can display 128 characters. All of which is pre-loaded into the EEPROM.
I'm having trouble with the communications part. How do I use USART to receive a data string and store into EEPROM one byte at a time? Plus I don't want to do the polling method.

Attached is the codings that i've written.
1. The New + new table file is working fine and i need to embed the USART part into it
2. The Usart RC file is the one I've written for serial communication with ZigBee.

The code should work as: Displaying out data from EEPROM and when new data is received, it will take it and store into EEPROM and then start displaying all over again. Please help. Thanks

Found quite a few errors in your code. I'll need some more info to fully correct them -

1) What crystal speed are you running? Or are you using the internal oscillator set to 4MHz?

2) Are you trying to run 9600bps asynchronous with a 4MHz oscillator?

Also...just so ya know, the receive interrupt flag (RCIF) gets cleared by the hardware as soon as you move the contents of RCREG into W so there's no need to clear it in software.
 
Last edited:
Hey, I'm using internal oscillator set to 4MHz, and also running at 9600bps asynchronous, yeah. is it possible?
Yeap, that's what i read too, but am not really sure thus the extra line.
The 'New with new table' file have already been added with the supposedly USART part at the logic which i understand. Somehow it can't seem to work. if i comment all the USART lines, my code will work perfectly fine.
Thanks, hope you can help.
 
Hey, I'm using internal oscillator set to 4MHz, and also running at 9600bps asynchronous, yeah. is it possible?
Yeap, that's what i read too, but am not really sure thus the extra line.
The 'New with new table' file have already been added with the supposedly USART part at the logic which i understand. Somehow it can't seem to work. if i comment all the USART lines, my code will work perfectly fine.
Thanks, hope you can help.

Yes it's possible...however your USART code wasn't set up properly. You had the wrong error value written to SPBRG and with the correct one in there and a 4MHz external frequency you need to enable BRGH=1.

You also didn't have the receive interrupt enable bit set in the PIE1 register, which is the Peripheral Interrupt Enable register.

Also...I added in the proper config word setup and the external frequency setup code to the PCON register in my code.

Now...when backing up the STATUS register in your ISR code, you need to use the instruction "swapf STATUS,W" when moving the contents of STATUS into the W register. This swaps the nibbles around into the W register and ensures that you transfer the data in STATUS to W without affecting the zero bit (bit Z). When restoring from the STATUS backup file, you again use "swapf STATUS_Save,W" to swap the nibbles once again prior to moving them from W back into the STATUS register.

Here is my corrected code. Try it out and let me know how it works -

Code:
		list		p=16F628
		include		<16F628.INC>
		__config	0x3D30

;Code Protection Disabled (CP)
;Data Code Protection Disabled (CPD)
;Low Voltage Programming Disabled (LVP)
;Brown Out Detection Disabled (BODEN)
;Watchdog Timer Disabled (WDTE)

;Power Up Timer Enabled (PWRTE)
;External Master Reset Enabled (MCLRE)
;Internal Oscillator (INTRC_OSC)

;RAM Address Labels

		cblock		0x20
				eefile		;0x20
				W_Save		;0x21
				STATUS_Save	;0x22
				PCLATH_Save	;0x23
		endc
;*******************************************************
;Reset and Interrupt Vectors/Interrupt Service Routine
;*******************************************************

		org		0x00		;reset vector
		goto		START
	
		org 		0x04		;interrupt vector
		movwf		W_Save		;back up current state of W register
		swapf 		STATUS,W
		movwf		STATUS_Save	;back up current state of STATUS register
		movfw 		PCLATH
		movwf 		PCLATH_Save	;back up current state of PCLATH register

		movlw		0x00
		movwf		eefile
		
		movfw		RCREG
		bsf		STATUS,RP0
		movwf		EEDATA
		bcf		STATUS,RP0
	
		movfw		eefile
		bsf		STATUS,RP0
		movwf		EEADR
		bcf		STATUS,RP0
		call		write
	
		movfw		PCLATH_Save
		movwf		PCLATH
		swapf		STATUS_Save,W
		movwf		STATUS
		movfw		W_Save
		retfie
;*******************************************************
;Port Setup
;*******************************************************

START		bsf		STATUS,RP0	;bank 1
		bsf		PCON,3		;set internal oscillator to 4MHz
		movlw		b'00100000'	;enable USART receive interrupt only
		movwf		PIE1
		bcf		STATUS,RP0	;bank 0
	
		movlw		b'11000000'	;enable unmasked peripheral interrupts only
		movwf		INTCON
;*******************************************************	
;Port A/B direction config
;*******************************************************

		bsf		STATUS,RP0	;bank 1
		movlw		b'00000000'
		movwf		TRISA		;Port A all outputs
		movlw		b'00000010'
		movwf		TRISB		;RB1 is the rx pin

;*******************************************************	
;USART config
;*******************************************************

		movlw		d'25'		;baud rate = 9600bps
		movwf		SPBRG
		clrf		TXSTA		;transmit disabled, asynchronous serial enabled
		bsf		TXSTA,BRGH	;Baud Rate High
		bcf		STATUS,RP0	;bank 0
	
		bsf		RCSTA,SPEN	;enable serial port
		bsf		RCSTA,CREN	;enable continuous receive
		bcf		RCSTA,RX9	;enable 9 bit receive
		
;*******************************************************
;Program Start
;*******************************************************


MAIN		goto		MAIN		;delete this instruction & put the first instruction of the rest of your program on this line

;*******************************************************
;Subroutines
;*******************************************************

write		bsf		STATUS,RP0	;select bank1  
		bsf		EECON1,WREN	;enable write
		bcf		INTCON,GIE	;disable all unmasked interrupts		
		movlw		0X55		;unlock codes
		movwf		EECON2
		movlw		0xAA
		movwf		EECON2
		bsf		EECON1,WR	;write begins
		bcf		EECON1,WREN	;disable write after write is complete
		bcf		STATUS,RP0	;select bank0		
		btfss		PIR1,EEIF	;wait for write to complete
		goto		$-1
		bcf		PIR1,EEIF	;clear EEPROM write interrupt flag
		bsf		INTCON,GIE	;enable all unmasked interrupts				
		return	
	
		end
 
Last edited:
Hey,
Thanks for pointing out my mistakes. However, the coding cannot work. But when i change the __config part of it, it worked, but the USART part is still problematic.

I've added certain lines as well to ensure that the program knows how many number of characters is stored in the EEPROM so that when displaying time, it would only display the new string of data that has been received and not just any data. Would the thing of it be a problem? Meaning to say that if I send a string of data 'abcd' would the program take A and place in EEPROM then directly take B and store and so on, without going through the main program? Meaning that the display will be empty while the transfer of data is in place and only after that, it will start displaying.

And also, even though the configuration of TRISB is 0x02, but the RB2/TX is not working as it should. It is acting as an Input pin.

I've attached the following code embedded in the code that you have given me.
Hope it is not too troublesome. Thanks
 

Attachments

  • USART WORK PLEASE.asm
    17.9 KB · Views: 162
OK...you're going to have to give me some time. The complete code has some serious errors in it. I'll rewrite the code...then I want you to look at my code and compare it to your code so that you can see the differences between the two in hopes of learning where you went wrong.

Now...are you using the USART to transmit serial data to the PC as well as receive serial data from the PC?

Also, why are you disabling external master clear (MCLRE)? If you disable external master clear, you need to put a pull up resistor on that pin anyway because it becomes an input only. It cannot be configured as an output to save putting a pull up resistor on that pin so I would recommend leaving that enabled and installing a 10K pullup resistor on the MCLR pin instead of trying to cheat the config by disabling it.

Do you also have a make/model/part number or a link to the data sheet for the display unit that you're using? If so can you post that information up?
 
Last edited:
Hey there,
Sure thing. Okay. The whole program supposed to work in this way. Initially in the PIC EEPROM, there will be data of which probably will write some welcome message or something. So the PIC will take out data from the EEPROM and display it out accordingly. The display size will be 14x7 where the 7 rows are driven by a 4017 decade counter, and the 14 columns are from the PIC, PORTA and PORTB. RA5 and RB1/RX are input only ports and RB1 will be connected to the ZigBee Dout pin, to receive data. When there is new data, the PIC will halt its operation, and take the new data and write in the EEPROM, clear its registers(reset) and start displaying the new data all over.

Only one way communication will occur from PC to PIC which is PC sends out serial data to PIC, PIC stores in EEPROM, and when transmission of data string is completed, PIC will display the message that is stored in EEPROM accordingly. The last byte of EEPROM will contain number of characters for the PIC to read to display the string data that was send earlier. So meaning if I initially in EEPROM there was 'abcd', the last byte will store 0x04 and if I send a new string of data, say '1234567', the last byte of EEPROM will store 0x07. So there will need to be a counter to keep track of the length of the incoming data string and be stored in EEPROM last byte. Data will be stored in ASCII characters. So, using lookup table will need to include the sublw command.

Only one way communication will occur from PC to PIC. PC will send data to PIC through ZigBee and PIC will not send any serial data out to ZigBee/PC.

On the MCLRE part, I'm using RA5 to get an input from the 4017 counter so that the PIC knows that it needs to clock the 4017 counter 3 times to ensure that the display will display out properly.

Attached is the hardware design(Hardware.JPG). For the dot-matrix, I'm using common cathode and the pin configuration is the same as most commonly used dot-matrix. The model number is 'TE 05457054N239M', but I can't find any datasheet on it. Please advice if my design is wrong. Thanks in advance.
 

Attachments

  • Hardware.JPG
    Hardware.JPG
    102.2 KB · Views: 275
Last edited:
Hey Jon,
If you don't mind me asking where is the errors in the complete code as previously mentioned? Greatly appreciate you taking the time to help me out.
Regards.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top