Jump to content
Sign in to follow this  
sorg

Problem with RS232 link with a 12F675

Recommended Posts

Hello,

I'am trying some programming with a 12F675 ...

 

I have the following test code:

 

#include <system.h>
#include "main.h"

//Config de la liason série
#pragma RS232_RXPORT GPIO
#pragma RS232_TXPORT GPIO
#pragma RS232_RXPIN 4
#pragma RS232_TXPIN 5
#pragma RS232_BAUD 4800
#pragma TRUE_RS232 1
#pragma CLOCK_FREQ 4000000

#define CR 0x0d //Retour Chariot

//Message de Bienvenue.
const char* bienvenue   = " Convertisseur: \0";

//Define device config block
asm
{
list p=PIC12F675
__config H'31C4'	
}


//////////////////////////////////////////////
// Interrupt handler
//////////////////////////////////////////////
void interrupt( void )
{
}

//////////////////////////////////////////////
// Main program entry
//////////////////////////////////////////////
main()
{
//Il faut charger la calibration de l'horloge interne:
asm {
 bsf STATUS, RP0
 call 3FFh
 movwf OSCCAL
 }

//Init interrupt registers
//!!! Sample interrupt initialization, correct for your application needs
option_reg = 7; 	 // set prescaler to 1:256

//Init ports
cmcon = 00000111b;  //Comparateur désactivé.
set_bit(trisio, 0); 	 //GP0 input  ->Mesure
set_bit(trisio, 1); 	 //GP1 input  ->Vref
clear_bit(trisio, 2);	//GP2 output ->LED
set_bit(trisio, 4); 	 //GP4 input  ->RS232-RX
clear_bit(trisio, 5);	//GP5 output ->RS232-TX
gpio = 0;    //Init à 0

//Config du CAN

clear_bit(adcon0, ADFM);	//On veut les 8 MSB
set_bit(adcon0, VCFG);  //On utilise VREF
clear_bit(adcon0, CHS0);	// C le channel 0 qui nous intéresse.
clear_bit(adcon0, CHS0);	
set_bit(adcon0, ADON);  //On active le convertisseur

clear_bit(ansel, ADCS2);	// On numérise à la cadence de l'oscillateur interne
set_bit(ansel, ADCS1);
set_bit(ansel, ADCS0);
clear_bit(ansel, ANS3);  //AN3 désactivé
clear_bit(ansel, ANS2);  //AN2 désactivé
set_bit(ansel, ANS1);  //AN1 activé
set_bit(ansel, ANS0);  //AN1 activé

delay_s(3);
//On affiche le message de Bienvenue.

char i=0;
while(bienvenue[i])
{
 putchar(bienvenue[i++]);
 delay_ms(10);
}
set_bit(adcon0, GO);  //on lance la capture
while(1) {
 while( (adcon0 & 2) != 0 )
 {
 }
 putchar(adresh);
 set_bit(gpio, 2);
 delay_ms(500);
 clear_bit(gpio, 2);
 delay_ms(500);
 delay_ms(10);
 set_bit(adcon0, GO);  //on lance la capture

}

}

 

 

 

I have met some problem: For example, I need to put a delay after each putchar command, in order to avoid garbage display on the terminal... is it normal ????

 

in the main loop ... while (1)....

The putchar command don't have any effect... Can you give a clue of the reason....

 

Thank you for reading me... and for your help!!

Share this post


Link to post
Share on other sites

Actually, I'm looking for the same thing!

I was wondering: Is the internal oscillator exact enough to do 9600 RS232 I/O at all?

I appreciate your help!

Alf

Share this post


Link to post
Share on other sites
Guest Dave

Alf,

 

I was wondering: Is the internal oscillator exact enough to do 9600 RS232 I/O at all?

Clock accuracy is not highly important with RS232 comms, because of its asynchronous nature.

This means that the receiver will resync on every piece of data, that why there are start bits.

As long as the clock is accurate to within 5% or less you should be OK.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...