#include <16F84A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8)
#byte PORTA=0x05
#byte PORTB=0x06
#bit CS = PORTB.7
#bit SCLK = PORTB.4
#bit MOSI = PORTB.5
#bit MISO = PORTB.2
#define POWERUP 0b00100
#define SETREC 0b10100
#define SETPLAY 0b11100
#define REC 0b10110
#define PLAY 0b11110
#define STOP 0b00110
#define STOPSLEEP 0b00010
#define TPUD 28
#define Duracion 2000
#define DIR 0
void envia (int8 comando, int8 direccion) {
int i=0;
int16 word;
int16 word_recibida=0;
word = ((int16)comando<<11) + (int16)direccion;
CS=0;
for (i=0; i<16; i++) {
MOSI = bit_test(word,i);
SCLK=1;
delay_us(1);
if (MISO)
bit_set(word_recibida,i);
SCLK=0;
}
CS=1;
printf ("%LX ",word_recibida);
}
void Reproducir() {
envia (POWERUP,DIR);
delay_ms(TPUD);
envia (SETPLAY,DIR);
envia (PLAY,DIR);
delay_ms(Duracion);
envia (STOPSLEEP,DIR);
}
void Grabar() {
envia (POWERUP,DIR);
delay_ms(TPUD);
envia (POWERUP,DIR);
delay_ms(TPUD);
delay_ms(TPUD);
envia (SETREC,DIR);
envia (REC,DIR);
delay_ms(Duracion);
envia (STOP,DIR);
}
void main()
{
char c;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
set_tris_b(0x4f);
CS=1;
SCLK=0;
// TODO: USER CODE!!
printf ("Grabador ISD4002\n\r\n\r> ");
while (1) {
if (kbhit()) {
c=getch();
switch (c) {
case 'g':
printf ("Grabando ");
Grabar();
break;
case 'r':
printf ("Reproduciendo ");
Reproducir();
break;
}
printf ("\n\r> ");
}
}
}