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.

12F1822 USART

mastero

Member
Hello friends,

I am trying to use 12F1822 usart but all i am getting on PC terminal is gibbrish.
in simulation it works fine.

Can someone pls tell me whats wrong here.

Thanx in advance.
cheers
mastero

AllDigital
TRISA = %00011000
PORTA = 0

Dim i As Byte
Symbol led = PORTA.5
UART1_Init 19200
WaitMs 100
led = 1

UART1_Write "START", CrLf
loop:
UART1_Get i
If UART1_Data_Ready > 0 Then
UART1_Write "Number: ", #i, CrLf
Toggle led
WaitMs 50
Endif
Goto loop
 
What's between the PIC UART and the PC? Do you have a MAX232 chip or a UART-USB converter chip?
 
Probably the most useful diagnostic for getting UART communications going is to send the character capital 'U' (0x55) in a repetitive loop. It is an alternating sequence of 1's and 0's so that you can reliably trigger a traditional oscilloscope to verify the bit timing and the inter character spacing.
 
Have you setup the CONFIG word/Oscillator Control Register for your oscillator settings?
Have you informed whatever compiler you're using of the frequency you're working at?
 
If you haven't specified anything, the default configuration will probably be the following:

Internal clock at 4Mhz and MCLR as digital input.

And then you have to control the overflow pin of the rs232 buffer or the data input will be blocked, but for the beginning if you do not supply a lot of data in a row it should work.

'12F1822
'Fuses
#define CONFIG1 = 0x0F84
#define CONFIG2 = 0x1CFF
'Clock Mhz
#define CLOCK_FREQUENCY = 4

AllDigital
TRISA = %00011000
PORTA = 0

Dim i As Byte
Symbol led = PORTA.5
UART1_Init 19200
WaitMs 100
led = 1

UART1_Write "START", CrLf

loop:
UART1_Get i
If UART1_Data_Ready > 0 Then
UART1_Write "Number: ", #i, CrLf
Toggle led
WaitMs 50
Endif
Goto loop
 
Internal clock at 4Mhz and MCLR as digital input.

'12F1822
'Fuses
#define CONFIG1 = 0x0F84
#define CONFIG2 = 0x1CFF
'Clock Mhz
#define CLOCK_FREQUENCY = 4

Not familiar with oshonsoft... will that #define set the OSCCON register?

That CONFIG1 word will set it to use the INTOSC, but the OSCCON register defaults to 500KHz MF
 
Try this other way:

The first thing is to remove the WaitMs 50.
Incorporate buffer error control.

'12F1822, v1.1
'Fuses
#define CONFIG1 = 0x0f84
#define CONFIG2 = 0x1cff
'Clock Mhz
#define CLOCK_FREQUENCY = 4

AllDigital
TRISA = %00011000
PORTA = 0

Dim i As Byte
Symbol led = PORTA.5
UART1_Init 19200
WaitMs 100
led = 1

UART1_Write "START", CrLf

loop:
UART1_Get i
If UART1_Data_Ready > 0 Then
UART1_Write "Number: ", #i, CrLf
Toggle led
'WaitMs 50
If RCSTA.OERR = True Then Call _error_usart()
Endif
Goto loop
End
'Manages the blocking of the USART in Rx mode
Proc _error_usart()
Dim _papelera As Byte
'More data entered than was extracted (blocked)
RCSTA.CREN = 0 'Disable, continua recepción
_papelera = RCREG 'Clear buffer usart
_papelera = RCREG
RCSTA.CREN = 1 'Enable, Continuous Receive Enable bit*/
End Proc
 
Last edited:

Latest threads

New Articles From Microcontroller Tips

Back
Top