#include <htc.h>
#include <pic16f628a.h>
#include <pic.h>
#include <stdio.h>
#include <stdlib.h>
#define PIC_CLK 10000000
#define TxPin RA0
#define RxPin RA1
#define BaudRate 9600
#include "SoftUart.c"
#define _XTAL_FREQ 4000000
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & MCLRE_ON & BOREN_OFF & LVP_OFF & CPD_OFF & CP_OFF);
void main (void)
{
const char * pantalla = "Mundo";
TRISA0 = 0;
TRISA1 = 1;
InitSoftUart();
Putst_s ("Hola"); // envia el string "Hola" al puerto serie
Putst_s ("\n"); // envia el salto de linea al puerto serie
Putst_s (pantalla); // envia el string apuntado por pantalla al puerto serie
}
#include "delayhd.h"
#if defined (PIC_CLK) && defined (BaudRate) && defined (TxPin) && defined (RxPin)
#if (PIC_CLK < 16000000)
#define BitDelay (1000000/BaudRate)
#define HalfBitDelay (500000/BaudRate)
#else
#define BitDelay (500000/BaudRate)
#define HalfBitDelay (250000/BaudRate)
#endif
#if (PIC_CLK == 4000000)
#define DelayReceivebit DelayUs(BitDelay-7)\
DelayUs(HalfBitDelay-7)
#if (BaudRate <= 19200)
#define DelayStartBit DelayUs(BitDelay-7)
#define DelaySendBit NDelayUs(BitDelay-18)
#elif (BaudRate == 28800)
#define DelayStartBit DelayUs(BitDelay-6)
#define DelaySendBit NDelayUs(BitDelay-18)
#elif (BaudRate == 38400)
#define DelayStartBit DelayUs(BitDelay-7)\
dly2u
#define DelaySendBit DelayUs(BitDelay-19)\
dly1u
#endif
#elif (PIC_CLK == 8000000)
#define DelayReceivebit DelayUs(BitDelay-7)\
DelayUs(HalfBitDelay-2)
#define DelayStartBit DelayUs(BitDelay-4)
#if (BaudRate <= 38400)
#define DelaySendBit NDelayUs(BitDelay-10)
#else //(BaudRate == 57600)
#define DelaySendBit NDelayUs(BitDelay-9)
#endif
#elif (PIC_CLK == 10000000)
#define DelayReceivebit DelayUs(BitDelay-7)\
DelayUs(HalfBitDelay)
#if (BaudRate <= 38400)
#define DelayStartBit DelayUs(BitDelay-4)
#define DelaySendBit NDelayUs(BitDelay-8)
#else //(BaudRate == 57600)
#define DelayStartBit DelayUs(BitDelay-3)
#define DelaySendBit NDelayUs(BitDelay-7)
#endif
#elif (PIC_CLK == 16000000) || (PIC_CLK == 20000000)
#if (PIC_CLK == 16000000)
#define DelayReceivebit DelayUs(BitDelay)\
DelayUs(BitDelay)\
DelayUs(BitDelay-5)
#else //(PIC_CLK == 20000000)
#define DelayReceivebit DelayUs(BitDelay)\
DelayUs(BitDelay)\
DelayUs(BitDelay-4)
#endif
#if (BaudRate <= 38400)
#define DelayStartBit DelayUs(BitDelay)\
DelayUs(BitDelay-2)
#define DelaySendBit NDelayUs(BitDelay)\
NDelayUs(BitDelay-4)
#else //(BaudRate == 57600)
#define DelayStartBit DelayUs(BitDelay)\
DelayUs(BitDelay-1)
#define DelaySendBit NDelayUs(BitDelay)\
NDelayUs(BitDelay-3)
#endif
#endif
/*
void InitSoftUart(void)
{
TxPin = 1;
}
*/
#define InitSoftUart TxPin = 1
unsigned char getch_s(void)
{
unsigned char contador = 7;
unsigned char letra = 0;
while (RxPin == 1);
DelayReceivebit;
do
{
if (RxPin == 1) letra += 128;
letra = letra >> 1;
contador--;
DelaySendBit;
}
while (contador > 0);
DelaySendBit;
return letra;
}
void putch_s (unsigned char data)
{
unsigned char contador = 8;
TxPin = 0;
DelayStartBit;
do
{
TxPin = data;
DelaySendBit;
data = data >> 1;
contador--;
}
while (contador > 0);
TxPin = 1;
DelayStartBit; //tiempo de espera del bit de stop
}
void putst_s (const char *word)
{
while (*word != 0)
{
putch_s(*word);
word++;
}
}
char * getst_s (char * st)
{
char * st1;
char caracter;
st1 = st;
do
{
caracter = getch_s();
if (caracter != '\r')
{
*st1 = caracter;
st1++;
}
*st1 = '\0';
}
while (caracter != '\r');
return st;
}
#else
#error Faltan definir parametros
#endif make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
make -f nbproject/Makefile-default.mk dist/default/production/UartSoft-V1.X.production.hex
make[2]: Entering directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
"C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 ../Uart-Soft_V1.X/main.c -q --chip=16F628A -P --outdir="build/default/production\_ext\1244268630" -N31 --warn=0 --runtime=default,+clear,+init,-keep,+osccal,-resetbits,-download,-stackcall,+clib --summary=default,-psect,-class,+mem,-hex --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --double=24 --float=24 --addrqual=ignore --mode=lite -g --asmlist "--errformat=%%f:%%l: error: %%s" "--msgformat=%%f:%%l: advisory: %%s" "--warnformat=%%f:%%l warning: %%s"
make[2]: *** [build/default/production/_ext/1244268630/main.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
../Uart-Soft_V1.X/main.c:29: error: function or function pointer required
../Uart-Soft_V1.X/main.c:29: error: pointer required
../Uart-Soft_V1.X/main.c:30 warning: function declared implicit int
make[2]: Leaving directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
make[1]: Leaving directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
BUILD FAILED (exit value 2, total time: 764ms)
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
#define PIC_CLK 10000000
#define TxPin RA0
#define RxPin RA1
#define BaudRate 9600
#define _XTAL_FREQ 4000000
#include "SoftUart.c"
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & MCLRE_ON & BOREN_OFF & LVP_OFF & CPD_OFF & CP_OFF);
void main (void)
{
const char * pantalla = "Mundo";
TRISA0 = 0;
TRISA1 = 1;
InitSoftUart();
putst_s ("Hola"); // envia el string "Hola" al puerto serie
putst_s ("\n"); // envia el salto de linea al puerto serie
putst_s (pantalla); // envia el string apuntado por pantalla al puerto serie
}make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
make -f nbproject/Makefile-default.mk dist/default/production/UartSoft-V1.X.production.hex
make[2]: Entering directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
"C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 ../Uart-Soft_V1.X/main.c -q --chip=16F628A -P --outdir="build/default/production\_ext\1244268630" -N31 --warn=0 --runtime=default,+clear,+init,-keep,+osccal,-resetbits,-download,-stackcall,+clib --summary=default,-psect,-class,+mem,-hex --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --double=24 --float=24 --addrqual=ignore --mode=lite -g --asmlist "--errformat=%%f:%%l: error: %%s" "--msgformat=%%f:%%l: advisory: %%s" "--warnformat=%%f:%%l warning: %%s"
../Uart-Soft_V1.X/main.c:26: error: function or function pointer required
../Uart-Soft_V1.X/main.c:26: error: pointer required
make[2]: *** [build/default/production/_ext/1244268630/main.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
make[1]: Leaving directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
BUILD FAILED (exit value 2, total time: 460ms)
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
#define PIC_CLK 10000000
#define TxPin RA0
#define RxPin RA1
#define BaudRate 9600
#define _XTAL_FREQ 4000000
#include "SoftUart.c"
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & MCLRE_ON & BOREN_OFF & LVP_OFF & CPD_OFF & CP_OFF);
void main (void)
{
const char * pantalla = "Mundo";
TRISA0 = 0;
TRISA1 = 1;
InitSoftUart();
putst_s ("Hola"); // envia el string "Hola" al puerto serie
putst_s ("\n"); // envia el salto de linea al puerto serie
putst_s (pantalla); // envia el string apuntado por pantalla al puerto serie
} make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
make -f nbproject/Makefile-default.mk dist/default/production/UartSoft-V1.X.production.hex
make[2]: Entering directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
"C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 ../Uart-Soft_V1.X/main.c -q --chip=16F628A -P --outdir="build/default/production\_ext\1244268630" -N31 --warn=0 --runtime=default,+clear,+init,-keep,+osccal,-resetbits,-download,-stackcall,+clib --summary=default,-psect,-class,+mem,-hex --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --double=24 --float=24 --addrqual=ignore --mode=lite -g --asmlist "--errformat=%%f:%%l: error: %%s" "--msgformat=%%f:%%l: advisory: %%s" "--warnformat=%%f:%%l warning: %%s"
../Uart-Soft_V1.X/main.c:20: error: function or function pointer required
make[2]: *** [build/default/production/_ext/1244268630/main.p1] Error 1
../Uart-Soft_V1.X/main.c:20: error: pointer required
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
make[1]: Leaving directory `C:/Users/guillote/Dropbox/Proyecto Final/Pic16F628A/Projecto Final/UartSoft-V1.X'
BUILD FAILED (exit value 2, total time: 2s)
Prueba llamando a la función IniSoftUart sin los paréntesis finales. En realidad no es una función sino que en la librería está definido con "#define".
#include <stdio.h>
#include <stdlib.h>
#include <htc.h>
#define PIC_CLK 10000000
#define TxPin PORTAbits.RA0
#define RxPin PORTAbits.RA1
#define BaudRate 9600
#include "uart.c"
#define _XTAL_FREQ 8000000 // esto es de HiTech para los delays
void init (void);
void main ()
{
OSCCONbits.IRCF2 = 1; //
OSCCONbits.IRCF1 = 1; // defino oscilador interno en 8 mhz
OSCCONbits.IRCF0 = 1; //
TRISAbits.TRISA0 = 0 ;
TRISAbits.TRISA1 = 1 ;
const char * pantalla = "Mundo";
InitSoftUart;
putst_s ("Hola"); // envia el string "Hola" al puerto serie
putst_s ("\n"); // envia el salto de linea al puerto serie
putst_s (pantalla); // envia el string apuntado por pantalla al puerto serie
}
void init (void)
{
ADCON0bits.ADON = 0; //
ADCON1bits.PCFG3 = 0; //
ADCON1bits.PCFG2 = 1; // pongo todas las entradas digitales porta
ADCON1bits.PCFG1 = 1; //
ADCON1bits.PCFG0 = 1; //
ADCON1bits.ADCS2 = 0; //
TRISB =1;
PORTB =0;
}
Gracias Angel -....
Los condicionales funcionan si defino dentro del mismo uart.c ...pero me da error en las funciones
:: warning: Omniscient Code Generation not available in Free mode
uart.c:175: error: function "_getch_s" redefined
(908) exit status = 1
uart.c:194: error: function "_putch_s" redefined
uart.c:212: error: function "_putst_s" redefined
uart.c:221: error: function "_getst_s" redefined
No entiendo porque me la da como redefinida