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.

Hello world not working (16F74)

Status
Not open for further replies.

imhereithink

New Member
Hi guys,

im trying to get the usart of my 16F74 to work, to test it i am sending out the good old " HELLO WORLD" but i am getting nothing through on my hyper terminal, and on my data comms tester im getting utter garbage :confused: I have attached the code for you to give me some helpful tips on where i might be going wrong.

Thanks in advance
 

Attachments

  • HW.asm
    4 KB · Views: 170
Shouldn't you configure bit 6 of PORTC as output?
Have you tried receiving data from the pc?
Are you using a max232 or similar?
 
Configure UART for 9600 bps (0.16% Error)


The Hiperterminal need the same config as PIC.

like @ Gayan Soyza say

"For me your DELAY is not good"


and don't forget the RS232 converter using a MAX232
something like this

**broken link removed**
 
Thanks for the comments guys,

I just tried simulating the delay routine and its getting hung up in their, i will try the simpler method as suggested and let you know how it goes :)
Also i am using the max 233 chip and the hyperterminal is set up the same as what im sending out.

Cheers
 
Right i just tried a simple delay:

DELAY MOVLW d'50'
MOVWF count1
lp1 DECF count1,F
btfss STATUS,Z
goto lp1
return

I tried simulating this but it never counts out, it just keeps looping :( any ideas as to whats wrong with this?
 
Use the delay code generator on the PICList. Here's the link:


Have you configured the TRISC register as I said earlier?
 
eng1 you are right, i never set portc up correctly, i assumed the pins would be set through setting the usart up . . . i assumed wrong :rolleyes: That will teach me for not reading the data sheet thouroghly. I will give that a shot and see what happens.

Thanks
 
Both RX and TX have to be set to input to configure the UART. I would get rid of the delay and just wait for TXIF to be set before writing to TXREG.

Have you set Hyperterminal to use no flow control?

Mike.
 
Pommie said:
Both RX and TX have to be set to input to configure the UART. I would get rid of the delay and just wait for TXIF to be set before writing to TXREG.
Mike, you are correct. I've just checked an old program I wrote and they're both set to input. Honestly I usually use software routienes to do RS-232 :rolleyes:
So that isn't be the problem with the program, because TRISC is 0xFF on reset...



I would check the value that is loaded into the SPBRG register! fosc is 20 MHz, isn't it?
 
Last edited:
imhereithink said:
Hi guys,

im trying to get the usart of my 16F74 to work, to test it i am sending out the good old " HELLO WORLD" but i am getting nothing through on my hyper terminal, and on my data comms tester im getting utter garbage :confused: I have attached the code for you to give me some helpful tips on where i might be going wrong.

Thanks in advance

hi,
Check the baud rate divider, you have 25?
>>>>>
#include <p16F74.inc> ;processor specific variable definitions
__config _HS_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF & _BODEN_OFF
;Configuration bits set as: Oscillator EXTERNAL 20MHz
BSF STATUS, RP0 ; Select Bank 1
BSF TXSTA, BRGH ; Enable high speed baud generator
MOVLW D'25' ;)Configure UART for 9600 bps (0.16% Error)
MOVWF SPBRG ;)
 
Last edited:
Hi Eric, I too noticed that... shouldn't it be 129?
The initialization would be correct for a 4 MHz crystal.
 
eng1 said:
Hi Eric, I too noticed that... shouldn't it be 129?
The initialization would be correct for a 4 MHz crystal.

hi eng1,
I agree, its '25' for a 4MHz xtal and '129' for 20MHz.

Eric
 
Thanks for pointing out all the silly mistakes guys, i totally forgot to change the baud rate divider, i used the setup from the 16F627 which ran 4MHz :rolleyes:
Iv also taken out the delay and used this instead as suggested:

MOVLW D'72' ;H
MOVWF TXREG
TEST1 BTFSS TXSTA,TXIF
GOTO TEST1

Now i just need to test it out. Thanks again guys you've ben a big help :)
 
I just went and tested it, and im getting most of the hello world message but theres a few extra characters thrown in from somewhere, this is what im getting through on the coms tester:
HHEMLLLNO@_&WWOCR^LDD
The other thing is im not getting any data through the hyper terminal, iv got this set to:

Bits per second: 9600
Data bits: 8
Parity: None
Stop bits: 1
Flow control: None

Any ideas?

Thanks again
 

Attachments

  • HW.asm
    4 KB · Views: 141
Last edited:
imhereithink said:
I just went and tested it, and im getting most of the hello world message but theres a few extra characters thrown in from somewhere, this is what im getting through on the coms tester:
HHEMLLLNO@_&WWOCR^LDD
The other thing is im not getting any data through the hyper terminal, iv got this set to:

Bits per second: 9600
Data bits: 8
Parity: None
Stop bits: 1
Flow control: None

Any ideas?

Thanks again
Hi Greg,
Try this, runs OK on my Oshonsoft simulator.

Eric
 
Last edited:
Hi eric,

I tried your code to no avail, it only sends out H permenantly :confused:
I also tried ammending my HW.asm since i noticed i was using the wrong register for the TXIF flag, i was using TXSTA when i should have been using PIR1 :rolleyes:
When i ran this program it now sends out:HLOO constantly. It seems that the data is being overwritten in the TXREG buffer? Am i testing the TXIF flag correctly?
 
Last edited:
imhereithink said:
Hi eric,

I tried your code to no avail, it only sends out H permenantly :confused:
I also tried ammending my HW.asm since i noticed i was using the wrong register for the TXIF flag, i was using TXSTA when i should have been using PIR1 :rolleyes:
When i ran this program it now sends out:HLOO constantly. It seems that the data is being overwritten in the TXREG buffer? Am i testing the TXIF flag correctly?

hi,
I use this subr on all my PIC prgms with no problems

;---- SERIAL UART ----
; Hardware Serial Communication Routines
TXRDY:
BTFSC PIR1,TXIF
GOTO XMIT1
GOTO TXRDY;busy,so loop
XMIT1:
MOVWF TXREG;send
RETURN

Are you sure that the receiving PC is OK?

Eric
 
Are you sure that the receiving PC is OK?

Im beginning to wander :rolleyes: lol I will try and use that subroutine in the HW.asm and see how far i get, if not i will try and use this on another pc.

Cheers
 
ericgibbs said:
hi,
I use this subr on all my PIC prgms with no problems

;---- SERIAL UART ----
; Hardware Serial Communication Routines
TXRDY:
BTFSC PIR1,TXIF
GOTO XMIT1
GOTO TXRDY;busy,so loop
XMIT1:
MOVWF TXREG;send
RETURN

Why two goto's?.

Change the BTFSC to BTFSS and delete the GOTO XMIT1 :D

Here are the routines from my RS232 tutorial.

Code:
XMIT_RS232  	btfss   PIR1,	TXIF 	      ;xmit buffer empty?
     		GOTO	XMIT_RS232            ;no, wait
     		MOVWF   TXREG		      ;now send
                RETURN

Rcv_RS232   	BTFSS   PIR1,	RCIF 	      ; check for received data
     		GOTO    Rcv_RS232
                MOVF    RCREG,	W
                RETURN
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top