Actualización 6/40/2014: Código fuente de la baliza:
/////////////////////////////////////////////////////////////////////////////////
//
// BALIZA IDENTIFICADORA EN CODIGO MORSE LU6FPJ - LU4FHJ
//
// MICRO: 16F877A ROSARIO 25/04/12
//
// NUEVA VERSION + DTMF modificado para 16F877A
//
//
// INCORPORADOS 2 x VOICE CHIP APR9600
//
//
/////////////////////////////////////////////////////////////////////////////////
// RB 0
// RB 1
// RB 2
// RB 3
// RB 4
// RB 5
// RB 6
// RB 7
// RA 0 TX
// RA 1 TONO
// RA 2
// RA 3
// RA 4
asm{
__FUSES _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_ON & _PWRTE_ON & _WDT_ON & _HS_OSC
}
//Timing settings
#pragma CLOCK_FREQ 20000000
//------------------------------------------------------------------------------
char PORTC@0x07;
char PORTD@0x08;
char PORTE@0x09;
char PIR1@0x0C;
char RCSTA@0x18;
char TXREG@0x19;
char RCREG@0x1A;
char ADRESH@0x1e;
char ADCON0@0x1f;
char CCPR1L@0x15;
char CCPR2L@0x1b;
char direc@0x20;
char valor@0x21;
//------------------------------------------------------------------------------
unsigned char aux;
unsigned char aux1;
unsigned char aux2;
unsigned char cursor1;
unsigned char cursor2;
unsigned char morse;
unsigned char frec;
unsigned char wpm;
unsigned int gx; // variables globales multiproposito
unsigned char gbx;
unsigned char gbt;
unsigned int frecuencia=1000; // desde 400 HZ hasta 1000 HZ
unsigned const char palabrasxm=12; // desde 4 palabras por minuto
//---------------------------TABLA MORSE----------------------------------------
//
//El primer uno a la izquierda es un marcador que no se reproduce
//
//a partir del mismo de izquierda a derecha 1=raya(DA) 0=punto (DI)
const unsigned char Table[59]={
00000001b,//032 espacio interpalabra 7 units
01101011b,//033 ! -ú-ú--
01010010b,//034 " ú-úú-ú
00111011b,//035 # --ú-- para usar la ¥
10001001b,//036 $ úúú-úú-
00000001b,//037 % No usado
00101000b,//038 & ú-úúú Wait
01011110b,//039 ' ú----ú
00110110b,//040 ( -ú--ú
01101101b,//041 ) -ú--ú-
00000001b,//042 * No usado
00101010b,//043 + ú-ú-ú
01110011b,//044 , --úú--
01100001b,//045 - -úúúú-
01010101b,//046 . ú-ú-ú-
00110010b,//047 / -úú-ú
00111111b,//048 0 -----
00101111b,//049 1 ú----
00100111b,//050 2 úú---
00100011b,//051 3 úúú--
00100001b,//052 4 úúúú-
00100000b,//053 5 úúúúú
00110000b,//054 6 -úúúú
00111000b,//055 7 --úúú
00111100b,//056 8 ---úú
00111110b,//057 9 ----ú
01111000b,//058 : ---úúú
01101010b,//059 ; -ú-ú-ú
00000001b,//060 < No usado
00110001b,//061 = -úúú-
00000001b,//062 > No usado
01001100b,//063 ? úú--úú
01011010b,//064 @ ú--ú-ú
00000101b,//065 A ú-
00011000b,//066 B -úúú
00011010b,//067 C -ú-ú
00001100b,//068 D -úú
00000010b,//069 E ú
00010010b,//070 F úú-ú
00001110b,//071 G --ú
00010000b,//072 H úúúú
00000100b,//073 I úú
00010111b,//074 J ú---
00001101b,//075 K -ú-
00010100b,//076 L ú-úú
00000111b,//077 M --
00000110b,//078 N -ú
00001111b,//079 O ---
00010110b,//080 P ú--ú
00011101b,//081 Q --ú-
00001010b,//082 R ú-ú
00001000b,//083 S úúú
00000011b,//084 T -
00001001b,//085 U úú-
00010001b,//086 V úúú-
00001011b,//087 W ú--
00011001b,//088 X -úú-
00011011b,//089 Y -ú--
00011100b //090 Z --úú
};
//------------------------FIN TABLA MORSE---------------------------------------
const unsigned char dtmf [16]={
'D',//
'1',//
'2',//
'3',//
'4',//
'5',//
'6',//
'7',//
'8',//
'9',//
'0',//
'*',//
'#',//
'A',//
'B',//
'C' //
};
//------------------------------------------------------------------------------
//
// FUNCIONES DE MANEJO DE DISPLAY
//
//------------------------------------------------------------------------------
void lcd_byte(char data,char control)
{char low,high;
low=data&15;
low=low<<4;
high=data&240;
if (control!=2){if(control==1){set_bit(high,2);set_bit(low,2);}
PORTD=high;
delay_ms(1);
set_bit(PORTD,3);
delay_ms(1);
clear_bit(PORTD,3);
delay_ms(1);
PORTD=low;
delay_ms(1);
set_bit(PORTD,3);
delay_ms(1);
clear_bit(PORTD,3);
delay_ms(1);
}
if (control==2){
PORTD=data;
delay_ms(1);
set_bit(PORTD,3);
delay_ms(1);
clear_bit(PORTD,3);
delay_ms(1);
}
}
void lcd_reset(void)
{
lcd_byte( 00001100b,0 ); // Display On/Off
lcd_byte( 00011000b,0 ); // Display Shift
lcd_byte( 00000001b,0 ); // Clear Display
lcd_byte( 00000110b,0 ); // Entry Mode Set
lcd_byte( 00101000b,0 ); // Funtion Set 4 bits 2 lines
lcd_byte( 00000010b,0 ); // Return Home
lcd_byte( 10000000b,0 ); // Set DD Ram Address
}
void lcd_init(void)
{
delay_ms(250);
delay_ms(250);
lcd_byte( 00110000b,2 );
delay_ms(5);
lcd_byte( 00110000b,2 );
delay_ms(1);
lcd_byte( 00110000b,2 );
lcd_byte( 00100000b,2 );
}
void mensaje (char mens)
{
char i=0;
// if(mens<20){lcd_reset();}
if(mens<20){ lcd_byte( 00000001b,0 ); // Clear Display
}
//else {lcd_byte( 10101000b,0 );}
// const char *SAMPLE ="0123456789ABCDEF------------------------0123456789ABCDEF";
const char *texto1 =" BIENVENIDO inicializando...";
const char *texto2 =" RADIOBALIZA ";
const char *texto7 =" CORTE ";
const char *texto8 =" VOICE ";
const char *texto9 =" PSK ";
const char *texto10=" SSTV ";
const char *texto11=" ID CW ";
const char *texto20=" ~ ";
if(mens==1 ){while(texto1 [i]!=0){lcd_byte(texto1 [i++],1);}}
if(mens==2 ){while(texto2 [i]!=0){lcd_byte(texto2 [i++],1);}}
if(mens==3 ){while(texto3 [i]!=0){lcd_byte(texto3 [i++],1);}}
if(mens==4 ){while(texto4 [i]!=0){lcd_byte(texto4 [i++],1);}}
if(mens==5 ){while(texto5 [i]!=0){lcd_byte(texto5 [i++],1);}}
if(mens==6 ){while(texto6 [i]!=0){lcd_byte(texto6 [i++],1);}}
if(mens==7 ){while(texto7 [i]!=0){lcd_byte(texto7 [i++],1);}}
if(mens==8 ){while(texto8 [i]!=0){lcd_byte(texto8 [i++],1);}}
if(mens==9 ){while(texto9 [i]!=0){lcd_byte(texto9 [i++],1);}}
if(mens==10){while(texto10[i]!=0){lcd_byte(texto10[i++],1);}}
if(mens==11){while(texto11[i]!=0){lcd_byte(texto11[i++],1);}}
if(mens==20){while(texto20[i]!=0){lcd_byte(texto20[i++],1);}}
}
void numero( int num )
{
lcd_byte( 10110100b,0 );//old value 10101101==45
// lcd_byte( '0' + (num/1000),1);
// lcd_byte( '0' + (num%1000)/100,1);
// lcd_byte( ',',1);
// lcd_byte( '0' + (num%100)/10,1);
lcd_byte( '0' + (num/100),1);
lcd_byte( '0' + (num%100)/10,1);
lcd_byte( '0' + (num%10),1);
}
//------------------------------------------------------------------------------
//
// FUNCIONES DE TIEMPO
//
//------------------------------------------------------------------------------
unsigned char segundosDTMF(unsigned int seg)
{
unsigned char stex1=255;
unsigned char stex2=255;
unsigned char dper=0;
unsigned int sdaux;
cursor1=0;
lcd_byte( 00000010b,0 ); // Return Home
mensaje(20);
lcd_byte( 00000010b,0 ); // Return Home
sdaux=seg+1;
seg=seg*20;
aux=0;
aux1=255;
aux2=0;
for(gx=0;gx<seg;gx++){
if(gx%20==0){
sdaux=sdaux-1;
if(dper==0){numero(sdaux);}
if(dper==1){mensaje(2);}
dper=dper-(dper>0);
}
clear_wdt();
delay_ms(50);
aux=(PORTB&10001111b);
if(aux>127){
aux1=aux&00001111b;
stex1=dtmf[aux1];
if(stex1!=stex2){
if(cursor1==16){
cursor1=0;
lcd_byte( 00000010b,0 ); // Return Home
mensaje(20);
lcd_byte( 00000010b,0 ); // Return Home
}
cursor2=128+cursor1;
lcd_byte(cursor2,0 );
lcd_byte(stex1,1);
cursor1++;
}
stex2=stex1;
}
else {
stex1=255;
stex2=255;
}
if((aux1>0)&&(aux1<6)){
if(aux2==0){return (aux1);}
}
if((aux1==9)&&(aux2==0))
{
aux2=20;
aux1=255;
}
aux2=aux2-(aux2>0);
if(aux1==5){
aux1=255;
if(aux2>0){mensaje(3);dper=15;}
aux2=0;
}
if(aux1==6){
aux1=255;
if(aux2>0){mensaje(4);dper=15;}
aux2=0;
}
if(aux1==7){
aux1=255;
if(aux2>0){mensaje(5);dper=15;}
aux2=0;
}
if(aux1==8){
aux1=255;
if(aux2>0){mensaje(6);dper=15;}
aux2=0;
}
}
aux1=0;
return 0;
}
unsigned char segundosff(unsigned int seg)
{
unsigned char stex1=255;
unsigned char stex2=255;
unsigned int sfaux;
unsigned char fper=0;
cursor1=0;
lcd_byte( 00000010b,0 ); // Return Home
mensaje(20);
lcd_byte( 00000010b,0 ); // Return Home
sfaux=seg+1;
seg=seg*20;
aux=0;
aux1=255;
aux2=0;
for(gx=0;gx<seg;gx++){
if(gx%20==0){
sfaux=sfaux-1;
if(fper==0){numero(sfaux);}
if(fper==1){mensaje(2);}
fper=fper-(fper>0);
}
clear_wdt();
delay_ms(50);
aux=(PORTB&10001111b);
if(aux>127){
aux1=aux&00001111b;
stex1=dtmf[aux1];
if(stex1!=stex2){
if(cursor1==16){
cursor1=0;
lcd_byte( 00000010b,0 ); // Return Home
mensaje(20);
lcd_byte( 00000010b,0 ); // Return Home
}
cursor2=128+cursor1;
lcd_byte(cursor2,0 );
lcd_byte(stex1,1);
cursor1++;
}
stex2=stex1;
}
else {
stex1=255;
stex2=255;
}
if((aux1==9)&&(aux2==0))
{
aux2=20;
aux1=255;
}
aux2=aux2-(aux2>0);
if(aux1==5){
aux1=255;
if(aux2>0){mensaje(3);fper=15;}
aux2=0;
}
if(aux1==6){
aux1=255;
if(aux2>0){mensaje(4);fper=15;}
aux2=0;
}
if(aux1==7){
aux1=255;
if(aux2>0){mensaje(5);fper=15;}
aux2=0;
}
if(aux1==8){
aux1=255;
if(aux2>0){mensaje(6);fper=15;}
aux2=0;
}
}
aux1=0;
return 0;
}
unsigned char segundosr(unsigned int seg)
{
seg=seg*20;
for(gx=0;gx<seg;gx++){
clear_wdt();
delay_ms(50);
aux=(PORTB&10001111b);
if(aux>127){
aux=aux&00001111b;
return (aux);}
}
aux=0;
return 0;
}
void segundosf(unsigned int seg)
{
seg=seg*10;
for(gx=0;gx<seg;gx++){
clear_wdt();
delay_ms(100);
}
}
void micropausa(void)
{
delay_us(frec);
delay_us(frec);
delay_us(frec);
delay_us(frec);
delay_us(frec);
}
void pausa (unsigned char c)
{
gbt=wpm;
for(gbx=0;gbx<c;gbx++)
{
clear_wdt();
while(gbt>0){
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
gbt--;
asm{nop}
micropausa();
PORTA=1;
micropausa();
}
}
}
void punto()
{
gbt=wpm;
while(gbt>0){
PORTA=3;
PORTA=3;
PORTA=3;
PORTA=3;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=3;
PORTA=3;
PORTA=3;
PORTA=3;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=3;
PORTA=3;
PORTA=3;
PORTA=3;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=3;
PORTA=3;
PORTA=3;
gbt--;
asm{nop}
micropausa();
PORTA=1;
micropausa();
}
pausa(1);
}
void raya()
{
gbt=3*wpm;
while(gbt>0){
PORTA=3;
PORTA=3;
PORTA=3;
PORTA=3;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=3;
PORTA=3;
PORTA=3;
PORTA=3;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=3;
PORTA=3;
PORTA=3;
PORTA=3;
micropausa();
PORTA=1;
PORTA=1;
PORTA=1;
PORTA=1;
micropausa();
PORTA=3;
PORTA=3;
PORTA=3;
gbt--;
asm{nop}
micropausa();
PORTA=1;
micropausa();
}
pausa(1);
}
void codec(unsigned char letra)
{
unsigned char c=7,x;
letra=letra&0x7F;
morse=Table[letra-0x20];
if(morse==0){morse=1;}
while(morse<0x80){morse=morse<<1;c--;}
morse=morse<<1;
// ú 1 unidad de tiempo
// - 3 unidades de tiempo
// gap intra caracter 1 unidad de tiempo
// gap entre caracteres 3 unidades de tiempo
// gap entre palabras 7 unidades de tiempo
//
// cada punto o raya termina con un gap de 1 para encadenarlo
// con el siguiente simbolo del caracter
// por eso agrego un gap de 2 al final para completar los 3
// luego de cada caracter
//
// de la misma manera agrego 4 para completar los 7 entre palabras
//
if(c==0){pausa(4);} //3 del gap de la ultima letra mas 4 = 7
else {
for(x=0;x<c;x++){if(morse<0x80){punto();} else {raya();}
morse=morse<<1;
}
pausa(2);
}
}
void codecc(unsigned char cletra)
{
if(cletra==0x20){
codec(cletra);
codec(cletra);
codec(cletra);
codec(cletra);
codec(cletra);
}
else {
codec(cletra);
}
}
void tx_morse(unsigned const char *texto)
{
unsigned char x=0;
cursor1=0;
cursor2=0;
lcd_byte( 00000010b,0 ); // Return Home
mensaje(20);
lcd_byte( 00000010b,0 ); // Return Home
while(texto[x]!=0){
codecc(texto[x]);
if(cursor1==16){
cursor1=0;
lcd_byte( 00000010b,0 ); // Return Home
mensaje(20);
lcd_byte( 00000010b,0 ); // Return Home
}
lcd_byte(texto[x],1);x++;
cursor1++;
}
}
void inicio_var(void)
{
frec=20000/frecuencia;
frec=frec*5;
gx=frec*40/1000; //periodo del loop (T*4)
gx=palabrasxm*frec;
wpm=30000/gx;
if(wpm>85){wpm=85;}
if(frec<100){frec=100;}
}
void power_on(void)
{
PORTA=5;
clear_wdt();
delay_ms(250);
clear_wdt();
PORTA=1;
delay_ms(250);
clear_wdt();
}
void power_off(void)
{
clear_wdt();
delay_ms(250);
clear_wdt();
delay_ms(250);
clear_wdt();
PORTA=0;
}
//******************************************************************************
void sstv(void)
{
mensaje(10);
power_on();
clear_bit(PORTB,6);
clear_wdt();
delay_ms(250);
clear_wdt();
delay_ms(250);
clear_wdt();
delay_ms(250);
set_bit (PORTB,6);
segundosf(40);
power_off();
}
//******************************************************************************
void psk(void)
{
mensaje(9);
power_on();
clear_bit(PORTB,4);
clear_wdt();
delay_ms(250);
clear_wdt();
delay_ms(250);
clear_wdt();
delay_ms(250);
set_bit (PORTB,4);
segundosf(18);
power_off();
}
//******************************************************************************
void voice(void)
{
mensaje(8);
power_on();
clear_bit(PORTB,5);
clear_wdt();
delay_ms(250);
clear_wdt();
delay_ms(250);
clear_wdt();
delay_ms(250);
set_bit (PORTB,5);
segundosf(11);
power_off();
}
//******************************************************************************
void callsign(void)
{
mensaje(11);
power_on();
tx_morse("VVV LU1FBT ");
tx_morse("LU4FHJ LU6FPJ ");
tx_morse("FF97QB ");
power_off();
}
//******************************************************************************
void callqap(void)
{
mensaje(7);
power_on();
tx_morse(" QAP ");
power_off();
}
//******************************************************************************
void main(void)
{
unsigned char maux=2;
cursor1=0;
cursor2=0;
//------------------------------------------------------------------------------
//
// SETEO DE PUERTOS
//
//------------------------------------------------------------------------------
asm
{
bsf STATUS,RP0
movlw b'10000110'
movwf ADCON1
movlw b'00000000'
movwf TRISD
bcf STATUS,RP0
}
set_bit( STATUS, RP0 );
set_tris_a( 00000000b );
set_tris_b( 10001111b );
OPTION_REG= 11111111b;
clear_bit( STATUS, RP0 );
PORTA=0;
PORTD=0;
PORTB=01110000b;
clear_wdt();
inicio_var();
lcd_init();
lcd_reset();
mensaje(1);
segundosf(2);
mensaje(2);
segundosf(2);
callsign();
mensaje(2);
while(1){
if(segundosDTMF(180)!=0){maux=aux1;}
if(maux==1){callqap();segundosff(300);maux=2;}
if(maux==2){voice() ;}
if(maux==3){psk() ;}
if(maux==4){sstv() ;}
if(maux==5){callsign();}
mensaje(2);
maux++;if(maux>5){maux=2;}
}
}

 




