|
|
View previous topic :: View next topic |
Author |
Message |
diegostreetbob
Joined: 05 Sep 2009 Posts: 11
|
Problem with serial on 12f629 |
Posted: Wed Nov 17, 2010 3:27 pm |
|
|
Hello friends,
I have a great problem with serial output, the hyperterminal shows for
example with printf("hola"); it shows ÷ symbol and with putc("hola");
it shows VHº symbol.
This is the code, the last line is printf("hola");
The hyperterminal is configured with 2400 8N1 hardware control.
Thanks in advance...
Code: |
#include <12F629.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPUT //No Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES BANDGAP_HIGH
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(internal=4000000)
#use rs232(baud = 2400,parity=N,xmit=PIN_A1,bits=8)
#byte porta=0x05
#byte trisa=0x85
#use fast_io(a)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
#zero_ram
int lectura(); //funcion lectura
int1 detecta(void); //funcion detectar pulso bajo
void memo(int v); //funcion memo, en v se almacenara el valor de leido una vez pulsado memo
void compara(int w); //función compara lectura con datos de eprom para identificar boton
int boton;
int boton1,boton2,boton3; //variable numero boton
int leido;
void main()
{
set_tris_a(0b110000);
int1 detectado;//recibira el valor del flagdetecta mediante el return de la funcion detecta()
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
set_timer1(0);
while(true)
{
if(bit_test(porta,4)==0) memo(leido);
else detectado=detecta();//llamada funcion detecta,y almacenado mediante el return el valor de flag detecta
leido=lectura();//llamamos funcion lectura y cargamos leido con valor y de lectura Return(y)
compara(leido);//llamamos a compara y le enviamos el valor de leido
}
}
int1 detecta(void)
{
int1 flagdetecta; //variable que se pondrá a 1 cuando haya sido detectado
star:
if(bit_test(porta,4)==0) memo(leido);//va a memorizar si pulsamos memo
set_timer1(0);
while(bit_test(porta,5)==0) //cuando el pulso es bajo, leemos el timer1 para medir el ancho de pulso
{
if(get_timer1()>18000)//retardo para detectar primer pulso largo bajo del mando
{
flagdetecta=1;//detectado
return(flagdetecta);//devolvemos el 1 de flagdetecta
}
}
goto star;
}
int lectura()
{
output_high(pin_a1);//para disparo del ikalogic
int codigo[3]; // Array de [3]Bytes, 24bits para la lectura del código boton1
int x; //para el for-next y lectura del array
int y;//almacenaremos codigo0+codigo1+codigo2
for(x=0;x<21;x++)//leemos 22bits, los 4 que faltan los obviamos con el retardo de 8000 de la linea 59.
{
delay_us(2439);//retardo para conincidir con el flanco tren de impulsos
shift_left(codigo,3,bit_test(porta,5));//registra lo que entra por portc,0 en los 2 bytes del array código
}
output_low(pin_a1);//para disparo ikalogic
y=codigo[0]+codigo[1]+codigo[2];
set_timer1(0);
output_low(pin_a0);//para encender el led hay que sacar 0
delay_ms(250);
output_high(pin_a0);
delay_ms(250);
output_low(pin_a0);//para encender el led hay que sacar 0
delay_ms(250);
output_high(pin_a0);
return(y);
}
void memo(int v)
{
boton++;//aunmenta una vez cada vez que entra en la funcion
if(boton>3) boton=1;
switch(boton)//depende las veces que se haya pulsado el boton de grabar se graba en una posición distinta
{
case 1:
write_eeprom(0x00,v);//grabamos leido(asignado a V) en la eprom
break;
case 2:
write_eeprom(0x01,v);
break;
case 3:
write_eeprom(0x02,v);
break;
}
{
output_low(pin_a0);
delay_ms(1000);
output_high(pin_a0);
delay_ms(1000);
output_low(pin_a0);
delay_ms(1000);
output_high(pin_a0);
}
}
void compara(int w)
{
output_low(pin_a0);//para encender el led hay que sacar 0
delay_ms(50);
output_high(pin_a0);
delay_ms(50);
output_low(pin_a0);//para encender el led hay que sacar 0
delay_ms(50);
output_high(pin_a0);
printf("hola");
} |
|
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
Re: Problem with serial on 12f629 |
Posted: Wed Nov 17, 2010 3:54 pm |
|
|
diegostreetbob wrote: |
problem with serial output, the hyperterminal |
please use another tool for debugging serial problems. Hyperterminal is not a good, reliable program for effective debugging. Using TeraTerm or similar is a much better plan.
diegostreetbob wrote: |
The hyperterminal is configured with 2400 8N1 hardware control. |
You should not be using hardware flow control; you should be using "no flow control".
diegostreetbob wrote: |
Code: |
#use delay(internal=4000000) |
|
what frequency is your board's oscillator?
diegostreetbob wrote: |
Code: |
#use rs232(baud = 2400,parity=N,xmit=PIN_A1,bits=8)
#byte porta=0x05
#byte trisa=0x85
#use fast_io(a)
#define GP1 PIN_A1
...
output_high(pin_a1);//para disparo del ikalogic
...
output_low(pin_a1);//para disparo ikalogic
|
|
why are you defining pin A1 as for use by RS232, and then playing with it via output_high/output_low?
jds-pic |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Thu Nov 18, 2010 5:34 am |
|
|
Add some further comments.
What voltage are you running the PIC at?. If not 5v, how accurate is the 12F629 internal oscillator warranted to be?. Is this good enough for RS232?.
What circuitry are you using to connect the PIC to the PC?. You something to provide the voltage shift, and inversion.
Best Wishes |
|
|
diegostreetbob
Joined: 05 Sep 2009 Posts: 11
|
|
Posted: Thu Nov 18, 2010 2:15 pm |
|
|
Ok,
tomorrow i will check all, thanks. |
|
|
diegostreetbob
Joined: 05 Sep 2009 Posts: 11
|
|
Posted: Fri Nov 19, 2010 2:37 pm |
|
|
Today I've tested and work fine.
Change the baudrate at 300 and no flow control, and only play with pin_a1 for tx.
Thanks
Best regards |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|