|
|
View previous topic :: View next topic |
Author |
Message |
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Re: PIC16F628 - DIP SWITCH |
Posted: Sat Sep 23, 2006 8:45 pm |
|
|
coseglio wrote: | ##Urgent## SOS#SOS |
Sounds like a homework.
coseglio wrote: | The while(1) loop i want is a infinite loop , but in my program execute only one and stop. I dont know wat is the problem with this. |
You're calling getc() in the main loop without calling kbhit() first. It could be that your program waits forever for the input from the serial port. Also, it might help to add something like printf("heartbeat\n\r"); for debugging purposes at the very top or very bottom of the loop outside any if statements. Or to toggle an LED for the same purpose. |
|
|
Guest
|
TEST |
Posted: Sun Sep 24, 2006 7:04 am |
|
|
Hi Kender. Thanks for the information.
Can tiy see now that is correct?
Code: | #include <16F628A.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP,NOMCLR
#include "usart.h"
#use delay (clock=4000000)
#use rs232(baud=9600,xmit=PIN_B2,rcv=PIN_B1)
SET_TRIS_A( 0x0F );
SET_TRIS_B( 0x0E );
unsigned char lerDip();
void main(void)
{
unsigned char saida;
unsigned char dados;
unsigned char aux = 0x00;
unsigned char mascara_a = 0xF0;
unsigned char entra;
unsigned char conf_dip;
int1 fotodiodo;
unsigned char endereco;
while(1)
{
conf_dip = lerDip();
aux = (conf_dip | mascara_a);
entra = 0x00;
entra = kbhit();
if(entra);
{
dados = getc();
}
if (dados == aux)
{
fotodiodo = 0;
fotodiodo = input(PIN_A0);
}
if (fotodiodo)
{
saida = 0xFF;
printf("%c",saida);
}
else
{ saida = 0x00;
printf("%c",saida);
}
}
}
unsigned char lerDip()
{
int8 a1;
int8 a2;
int8 a3;
int8 res;
res = 0x00;
res |= a1;
if (a1)
res |= (a2 << 1);
if (a2)
res |= (a3 << 2);
if (a3)
return res;
} |
|
|
|
|
|
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
|