Last active
February 3, 2021 18:32
-
-
Save bananu7/8b6329c4c0e2f7a30ddea1a95123bb10 to your computer and use it in GitHub Desktop.
The code for VW Gamma V radio unlock (CD changer emulation)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <avr/wdt.h> | |
#include <util/delay.h> | |
#include <SPI.h> | |
//#define pSS | |
#define pDATA 0b00001000 | |
#define pCLK 0b00100000 | |
typedef int8_t INT8; //char | |
typedef uint8_t UINT8; //unsigned char | |
typedef int16_t INT16; //int | |
typedef uint16_t UINT16; //unsigned int | |
typedef int32_t INT32; //long | |
typedef uint32_t UINT32; //unsigned long | |
typedef int64_t INT64; //long long | |
typedef uint64_t UINT64; //unsigned long long | |
void send_byte(UINT8 c) | |
{ | |
SPDR = c; | |
loop_until_bit_is_set(SPSR, SPIF); //wait for transmission complete | |
_delay_us(700); //335 700 | |
return; | |
} | |
void send_package(UINT8 c0, UINT8 c1, UINT8 c2, UINT8 c3, UINT8 c4, UINT8 c5, UINT8 c6, UINT8 c7) | |
{ | |
send_byte(c0); | |
send_byte(c1); | |
send_byte(c2); | |
send_byte(c3); | |
send_byte(c4); | |
send_byte(c5); | |
send_byte(c6); | |
send_byte(c7); | |
return; | |
} | |
int main(void) | |
{ | |
//init ports | |
//DDRB = pDATA|pCLK; | |
DDRB = 0b00111111; //Port B (pins 13-8) ouputs. first two 0's b/c no pins there | |
//PORTB = pDATA|pCLK|pSS; | |
PORTB = 0b00111111; | |
//analog comparator Off | |
ACSR = (1<<ACD); | |
//init watchdog timer | |
wdt_enable(WDTO_1S); | |
wdt_reset(); | |
//init spi | |
//SPCR = (1<<SPE)|(1<<MSTR)|(1<<CPOL)|(1<<SPR0); //enable SPI, Master, clock=fcpu/8=8us | |
SPCR = (1<<SPE)|(1<<MSTR)|(1<<CPOL)|(1<<SPR0)|(1<<SPR1); //enable SPI, Master, clock=fcpu/8=8us | |
SPSR = (1<<SPI2X); | |
//send init packages | |
_delay_ms(10); | |
_delay_ms(10); | |
send_package(0x74,0xBE,0xFE,0xFF,0xFF,0xFF,0x8F,0x7C); //idle | |
_delay_ms(10); | |
send_package(0x34,0xFF,0xFE,0xFE,0xFE,0xFF,0xFA,0x3C); //load disc | |
_delay_ms(10); | |
send_package(0x74,0xBE,0xFE,0xFF,0xFF,0xFF,0x8F,0x7C); //idle | |
for(;;) | |
{ | |
wdt_reset(); | |
_delay_ms(10); | |
// disc trk min sec | |
send_package(0x74,0xBE,0xFE,0xFF,0xFF,0xFF,0xCF,0x7C); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#define CLK_PIN 13 | |
#define DATA_OUT_PIN 11 | |
#define ATTINY 1 | |
#ifdef ATTINY | |
#define CLK_PIN 2 | |
#define DATA_OUT_PIN 1 | |
#include <SoftSPI.h> | |
SoftSPI mySPI(DATA_OUT_PIN, 2, CLK_PIN); | |
#define SPI mySPI | |
#endif | |
void setup() { | |
pinMode(CLK_PIN, OUTPUT); | |
pinMode(DATA_OUT_PIN, OUTPUT); | |
SPI.begin(); | |
SPI.setClockDivider(SPI_CLOCK_DIV16); | |
SPI.setDataMode(SPI_MODE2); | |
SPI.setBitOrder(MSBFIRST); | |
} | |
void send_byte(uint8_t c) { | |
SPI.transfer(c); | |
delayMicroseconds(700); | |
} | |
void send_package(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5, uint8_t c6, uint8_t c7) | |
{ | |
send_byte(c0); | |
send_byte(c1); | |
send_byte(c2); | |
send_byte(c3); | |
send_byte(c4); | |
send_byte(c5); | |
send_byte(c6); | |
send_byte(c7); | |
} | |
void loop() { | |
// disc trk min sec | |
send_package(0x74,0xBE,0xFE,0xFF,0xFF,0xFF,0xCF,0x7C); | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment