Skip to content

Instantly share code, notes, and snippets.

@mazurio
Created March 10, 2014 21:54
Show Gist options
  • Save mazurio/9475275 to your computer and use it in GitHub Desktop.
Save mazurio/9475275 to your computer and use it in GitHub Desktop.
#include <18f2420.h>
#device PASS_STRINGS = IN_RAM
#include <18f2420_registers.h>
#fuses INTRC_IO, NOBROWNOUT, NOPROTECT, NOIESO, NOWDT, NOLVP
#use delay(clock=8000000)
#use rs232(baud=7200, xmit=PIN_C6, rcv=PIN_C7, UART1, errors)
//media library, a compatable media library is required for FAT.
#use fast_io(c)
#define MMCSD_PIN_SCL PIN_C3 //o
#define MMCSD_PIN_SDI PIN_C4 //i
#define MMCSD_PIN_SDO PIN_C5 //o
#define MMCSD_PIN_SELECT PIN_C1 //o
#include <mmcsd.c>
//#include <input.c>
#include <fat.c>
// Bit 0 at SSPTAT module.
#bit BF = 0xFC7.0
// #bit BF = SSPSTAT.0
//
// Configure SPI for sending data to VLSI MP3 decoder (SDI)
//
void VLSIDataSPI() { setup_spi (SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4); }
//
// Configure SPI for sending data to VLSI control interface (SCI)
// and for communicating with SD/MMC interface
//
void SPI() { setup_spi (SPI_MASTER | SPI_H_TO_L | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16); }
char write(char d)
{
printf("Write");
SSPBUF=d;
while(bit_test(SSPSTAT, 0) == 1) {
printf("Bit test\r\n");
}
// while(input(BF) == 0) {
// printf("LOOP\r\n");
// }
printf("Done.\r\n");
// 0x53, 0xef, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00
spi_write(0x53);
spi_write(0xef);
spi_write(0x6e);
spi_write(0x3e);
spi_write(0x00);
spi_write(0x00);
spi_write(0x00);
spi_write(0x00);
return SSPBUF;
}
void main(void)
{
fat_init();
// disp_folder_contents('/');
while(TRUE)
{
printf("Loop:\r\n");
}
}
// void main(void)
// {
// // SPI();
// BYTE v;
// printf("\n\rSSPSTAT: %2X SSPBUF: %2X TRISC: %2X PORTC: %2X\n\r", SSPSTAT, SSPBUF, TRISC, PORTC);
// if(mmcsd_init())
// {
// printf("Could not init MMCSDC.\r\n");
// } else {
// printf("MMCSDC init.");
// }
// mmcsd_print_csd();
// mmcsd_print_cid();
// // uint32_t address = 0x3f000; // mp3 file
// uint32_t address = 0x6600; // fat
// uint16_t i;
// int counter = 32;
// const char *dir = '/';
// disp_folder_contents(dir);
// // while(TRUE)
// // {
// // // Is SD card inserted?
// // // if(input(PIN_A6)) {
// // // printf("[F]"); // False
// // // } else {
// // // printf("[T]"); // True
// // // }
// // // if(input(SSPTAT_BF)) {
// // // printf(SSPTAT_BF);
// // // } else {
// // // printf("Low");
// // // }
// // //Read byte from SD card starting at given address.
// // // if(mmcsd_read_byte(address++, &v) == 0)
// // // {
// // // printf("%X at %X\r\n", v, address);
// // // }
// // // set MP3_RESET at PORTB.1 low
// // // then set it HIGH
// // // VS1001k
// // VLSIDataSPI();
// // // MP3 RESET LOW.
// // output_low(PIN_B1);
// // // SET MP3 HIGH.
// // output_high(PIN_B1);
// // // WHEN MP3 DATA REQUEST IS HIGH.
// // // MP3 DECODER IS READY TO RECEIVE AT LEAST 32 BYTES OF DATA.
// // // if(input(PIN_B0) == 1)
// // // {
// // printf("Send 32 bytes, as PIN_B0 is high.\r\n");
// // output_high(PIN_C2);
// // output_high(PIN_C5);
// // // sending a byte.
// // // spi_write(v);
// // // 0x53, 0xef, 0x6e, 0x3e,
// // // bsync = 0;
// // //
// // // SSPBUF = 0b00101111;
// // // while(SSPTAT_BF == 0);
// // // SSPTAT_BF = 0;
// // output_low(PIN_B2);
// // // write(v);
// // // 0x53, 0xef, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00
// // printf("Write?");
// // write(v);
// // // bsync = 1
// // // if(input(SSPTAT_BF)) {
// // // output_low(PIN_B2);
// // // }
// // output_low(PIN_C5);
// // output_low(PIN_C2);
// // // }
// // // delay_ms(255);
// // // delay_ms(255);
// // // delay_ms(255);
// // SPI();
// // }
// }
// void spi_chargecurrent(void) {
// unsigned char dummy1,dummy2;
// LATAbits.LATA5 = 0;//set ss low
// SSPBUF = 0b00101111;//write to the 1st byte to the buffer
// while (SSPSTATbits.BF == 0); // wait to complete
// dummy1 = SSPBUF; // clear BF flag
// SSPBUF = 0b11010000; //write to the 2nd byte to the buffer
// while (SSPSTATbits.BF == 0); // wait to complete
// dummy1 = SSPBUF; // clear BF flag
// LATAbits.LATA5 = 1;//set ss high to finish
// }
// void main(void)
// {
// // Configure SPI.
// SPI();
// char buffer[255];
// char opt_buffer[255];
// int i; // pointer to the buffer
// i = fat_init();
// if(i) {
// printf("\r\n\nERROR INITIALIZING FAT\r\n\n");
// }
// while(TRUE)
// {
// printf("MP3 Player.");
// }
// }
// // VLSIDataSPI();
// // uint8_t v;
// // uint16_t size;
// // BYTE value;
// // if(mmcsd_init())
// // {
// // printf("Could not init MMCSDC.\r\n");
// // } else {
// // printf("MMCSDC init.");
// // }
// // while(TRUE)
// // {
// // // returns 0 if Ok, non-zero if error.
// // if(mmcsd_read_data(0x3f000, 32, &v) == 0)
// // {
// // printf("Read data ok.");
// // // printf("Data: '%X'\r\n", v);
// // } else {
// // printf("read data not ok.");
// // }
// // printf("Data: '%X'\r\n", v);
// // }
// // while(TRUE)
// // {
// // //printf("Set low, then high.");
// // // set MP3_RESET at PORTB.1 low
// // // then set it HIGH
// // output_low(PIN_B1);
// // output_high(PIN_B1);
// // // Check if MP3_DATA_REQUEST is high.
// // // The MP3 DECODER is ready to receive at least 32 bytes of data.
// // mmcsd_read_byte(0x3f000, &value);
// // printf("Byte at 0x3f000: '%X'\r\n", value);
// // //printf("Damian Test\r\n");
// // if(bit_test(PORTB0, 0))
// // {
// // //printf("2.Send 32 bytes, is HIGH!\r\n");
// // // Set MP3 DATA SELECT to HIGH while transmitting data.
// // output_high(PIN_C2);
// // // Transmission:
// // // Serial Data Out (SDO) at PORTC.5
// // output_high(PIN_C5);
// // // 0x53, 0xef, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00
// // spi_write(0x6e);
// // spi_write(0x6e);
// // spi_write(0x6e);
// // spi_write(0x6e);
// // spi_write(0x6e);
// // spi_write(0x6e);
// // spi_write(0x6e);
// // spi_write(0x6e);
// // output_low(PIN_C5);
// // // End of data transmission, set MP3 DATA SELECT to LOW.
// // output_low(PIN_C2);
// // } else {
// // // printf("2.ITS LOW\r\n");
// // }
// // delay_ms(255);
// // delay_ms(255);
// // delay_ms(255);
// // delay_ms(255);
// // delay_ms(255);
// // delay_ms(255);
// // delay_ms(255);
// // delay_ms(255);
// // delay_ms(255);
// // delay_ms(255);
// // }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment