Lyckades lösa det utifrån krilles kod (Tack!)
Än sålänge med många felande kommentarer, massor med oanvända variablar, utkommenterad kod och vissa saker som inte funkar (lätt att fixa men dock tråkigt så det får bli en annan dag)
Kod: Markera allt
bit ReciveDone,ReciveDone2,OldReciveRadio,ReciveRadioNew,OnOFFCode,Package,RadioBit,OldRadioBit,RadioBitValid,Alternate;
char RaidoBitCounter,ChannelCode,HouseCode,Change,TMR1L_TMP,TMR1H_TMP,sID;
unsigned long senderID;
//////////////////////////////////////////////////////////////////////////////////////////
// InterruptFunction
//
//////////////////////////////////////////////////////////////////////////////////////////
void interrupt () {
ReciveRadioNew = PORTB.B0;
if(INTCON.INTF) {
// We handle all radio stuff from hear
// We are only looking for new transmisions if the old one is handeled
//if( ReciveDone == 0 ) {
//We save the counter value then the interupt vas dicovered
//The counter is still runing thats way we nead to save the value
TMR1H_TMP = TMR1H;
//We resets the counter so we can measure the next puls with
TMR1L = 0x00;
TMR1H = 0x00;
//High, should be 230-320µS (+-50µS = 23-46)
if (TMR1H_TMP > 1 && TMR1H_TMP < 6) {
RadioBitValid = 1;
RadioBit = 1;
}
//Low, should be 170-200µS (+-50µS = 15-31) for High or 920-1210µS (+-100µS = 103-164) for Low
else if (TMR1H_TMP > 9 && TMR1H_TMP < 16) {
RadioBitValid = 1;
RadioBit = 0;
} else {
UART1_Write_Text("\r");
UART1_Write(TMR1H_TMP);
Change = 0;
Package = 0;
RaidoBitCounter = 0;
RadioBitValid = 0;
}
if (RadioBitValid) {
//UART1_Write(RadioBit);
// Bit 0-51 is Sender ID
if (RaidoBitCounter < 52) {
if (Alternate) {
senderID |= RadioBit << sID;
Alternate = 0;
sID++;
} else {
Alternate = 1;
}
}
// Bit 52-53 is Group
else if (RaidoBitCounter == 53) {
//OnOFFCode = RadioBit;
}
// Bit 54-55 is On/Off
else if (RaidoBitCounter == 55) {
OnOFFCode = RadioBit;
}
// Bit 56-59 is Channel
else if (RaidoBitCounter == 56) {
ChannelCode |= RadioBit << 0;
}
else if (RaidoBitCounter == 57) {
ChannelCode |= RadioBit << 1;
}
else if (RaidoBitCounter == 58) {
ChannelCode |= RadioBit << 2;
}
else if (RaidoBitCounter == 59) {
ChannelCode |= RadioBit << 3;
}
// Bit 60-63 is Button
else if (RaidoBitCounter == 60) {
HouseCode |= RadioBit << 0;
}
else if (RaidoBitCounter == 61) {
HouseCode |= RadioBit << 1;
}
else if (RaidoBitCounter == 62) {
HouseCode |= RadioBit << 2;
}
else if (RaidoBitCounter == 63) {
HouseCode |= RadioBit << 3;
UART1_Write_Text("5");
UART1_Write_Text(senderID);
UART1_Write_Text("6");
UART1_Write(OnOFFCode);
UART1_Write(ChannelCode);
UART1_Write(HouseCode);
UART1_Write_Text("7");
}
RaidoBitCounter++;
}
INTCON.INTF = 0;
//Save The bit status for next time
//OldReciveRadio = ReciveRadioNew;
//OldRadioBit = RadioBit;
//}
}
}
void main () {
//
// Some setup commands goes here ..
// ex. ...
CMCON = 7; // Turn off the comparators
PORTA = 0; // Define states of processor pins ...
TRISA = 0; // Define in (1) or out (0) of processor pins ...
PORTB = 255; // Define states of processor pins ...
TRISB = 0; // Define in (1) or out (0) of processor pins ...
TRISB.B0 = 1; // Define in (1) or out (0) of processor pins ...
PORTB = 255; // Define states of processor pins ...
UART1_Init(19200); // Initialize UART module at 19200 bps
Delay_ms(100); // Wait for UART module to stabilize
T1CON = 0b00011001;// Enable timer1 with a prescaler of 1:8
//option.INTEDG = 1; // Enable RB interrupt.
INTCON.INTE=1; // Pheripheral enable interrupt.
INTCON.GIE=1; // Global enable interrupt
//Clear some variables to be shure of their state
ReciveDone = 0;
OldReciveRadio = 0;
Change = 0;
Alternate = 1;
sID = 0;
senderID = 0;
ChannelCode = 0;
HouseCode = 0;
while(1) {
if(ReciveDone == 1) {
ReciveDone = 0;
}
}
}
Gnäll inte på utseendet. Först ska det funka (vilket det nästan gör, måste bara splitta sender idt så att det flyter bättre över serieporten) och sen ska det bli snabbt och vackert
Ska lägga in gamla nexa oxå men 2000 var intressantast för stunden.