More Related Content Similar to Diseqc x/USALS Interface Code Similar to Diseqc x/USALS Interface Code (16) More from Jakab Zsolt (8) Diseqc x/USALS Interface Code1. Diseqc x/USALS interface
ZSOLT LEVENTE Page 1
V 1
Short description:
This equipment is intended to interface Diseqc & Usals compatible
receivers with old parabolic dish actuators.
The interface takes its power supply from IF coax which connects receiver and
LNB. When valid data comes from receiver the interface powers up and the
decoded command is executed.
3. Diseqc x/USALS interface
ZSOLT LEVENTE Page 3
Code :
//--------------------------------------------------------------------------------------
// HED'S
//--------------------------------------------------------------------------------------
#include <math.h>
//--------------------------------------------------------------------------------------
// DEF'S
//--------------------------------------------------------------------------------------
#define goE RB7
#define in RB6
#define goW RB4
#define out RB3
#define power RB5
#define inHall RA0
//----------------------------------------------------------------------------------
#define frame1 0xE0 // Command from Master, No reply required, First transmission
#define frame2 0xE1 // Command from Master, No reply required, Repeated transmission
#define frame3 0xE2 // Command from Master, Reply required, First transmission
#define frame4 0xE3 // Command from Master, Reply required, Repeated transmission
#define frame5 0xE4 // Reply from Slave, “OK”, no errors detected
#define frame6 0xE5 // Reply from Slave, Command not supported by slave
#define frame7 0xE6 // Reply from Slave, Parity Error detected - Request repeat
#define frame8 0xE7 // Reply from Slave, Command not recognised - Request repeat
//--------------------------------------------------------------------------------------
4. Diseqc x/USALS interface
ZSOLT LEVENTE Page 4
// GLOBAL'S
//--------------------------------------------------------------------------------------
char timer=0;
int steptimer=0, timedMove=0;
char REC_FRAME=0,REC_ADDRESS=0,REC_CMD=0,REC_DATA=0;
//--------------------------------------------------------------------------------------
// PREDEF'S
//--------------------------------------------------------------------------------------
unsigned char DISEQC_REC (void);
void Halt(void);
void LimitsOff(void);
void PosStat(void);
void LimitE(void);
void LimitW(void);
void DriveEast(void);
void DriveWest(void);
void Storenn(void);
void Gotonn(void);
void Gotoxx(void);
void SetPosns(void);
void CommandTask (void);
void Reply1(void);
void Reply2(void);
void ReqReTransm(void);
void Setup(void);
5. Diseqc x/USALS interface
ZSOLT LEVENTE Page 5
//***********************************************************************************
**
// INTERUPT SERVICE ROUTINES
//***********************************************************************************
**
static void interrupt
isr(void)
{
if(T0IF)
{
T0IF=0;
// WriteTimer0(64098); // 1ms
if(timer>0)timer--;
if(steptimer>0)steptimer--;
if(timedMove && !steptimer)Halt();
}
}
//***********************************************************************************
**
// return x Byte received
OK
// 0 Timedout
6. Diseqc x/USALS interface
ZSOLT LEVENTE Page 6
// 'P' parity error
//***********************************************************************************
**
unsigned char DISEQC_REC (void)
{
unsigned char par=1,inbit=0;
int result=0,i=0;
REC_FRAME=0;REC_ADDRESS=0;REC_CMD=0;REC_DATA=0;
while(1)
{
timer=2;
while(!in){ if(!timer)goto Rxend;if(in==1)break;}
TMR1L=0;
__delay_us(1050);//1050us
result=TMR1L;
if(result>19 & result<25)inbit=0;
if(result>9 & result<14)inbit=1;
if(i>=0 && i<8) {
REC_FRAME=REC_FRAME<<1;
if(inbit==1){REC_FRAME=REC_FRAME | 0x01;par=~par;}
}
if(i==8) { if(par==inbit)return 'P'; par=1;}
if(i>=9 && i<17) {
REC_ADDRESS=REC_ADDRESS<<1;
if(inbit==1){REC_ADDRESS=REC_ADDRESS | 0x01;par=~par;}
7. Diseqc x/USALS interface
ZSOLT LEVENTE Page 7
}
if(i==17){if(par==inbit)return 'P'; par=1;}
if(i>=18 && i<26) {
REC_CMD=REC_CMD<<1;
if(inbit==1){REC_CMD=REC_CMD | 0x01;par=~par;}
}
if(i==26){if(par==inbit)return 'P'; par=1;}
if(i>=27 && i<35) {
REC_DATA=REC_DATA<<1;
if(inbit==1){REC_DATA=REC_DATA | 0x01;par=~par;}
}
if(i==35){if(par==inbit)return 'P'; par=1;}
i++;
}
Rxend:
if (i==0)return 0;
else return i;
}
//***********************************************************************************
**
// Identify command,execute & reply if needed
8. Diseqc x/USALS interface
ZSOLT LEVENTE Page 8
//***********************************************************************************
**
void CommandTask ()
{
switch (REC_CMD)
{
case 0x60: Halt(); break;
case 0x63: LimitsOff(); break;
case 0x64: PosStat(); break;
case 0x66: LimitE(); break;
case 0x67: LimitW(); break;
case 0x68: DriveEast(); break;
case 0x69: DriveWest(); break;
case 0x6A: Storenn(); break;
case 0x6B: Gotonn(); break;
case 0x6E: Gotoxx(); break;
case 0x6F: SetPosns(); break;
}
switch (REC_FRAME)
{
case frame1: break;
case frame2: break;
case frame3: Reply1(); break;
case frame4: Reply2(); break;
}
}
9. Diseqc x/USALS interface
ZSOLT LEVENTE Page 9
//***********************************************************************************
**
// Stop Positioner movement
//***********************************************************************************
**
void Halt()
{
goE=goW=0;
}
//***********************************************************************************
**
// Disable Limits
//***********************************************************************************
**
void LimitsOff()
{
}
//***********************************************************************************
**
// Read Positioner Status Register
//***********************************************************************************
**
void PosStat()
{
}
10. Diseqc x/USALS interface
ZSOLT LEVENTE Page 10
//***********************************************************************************
**
// Set East Limit
//***********************************************************************************
**
void LimitE()
{
}
//***********************************************************************************
**
// Set West Limit
//***********************************************************************************
**
void LimitW()
{
}
//***********************************************************************************
**
// Drive Motor East with optional: timeout (REC_DATA>0) [s]
// steps (REC_DATA<0) [engle]
//***********************************************************************************
**
void DriveEast()
{
Halt();
11. Diseqc x/USALS interface
ZSOLT LEVENTE Page 11
goE=1;goW=0;
if(REC_DATA==0){ steptimer=0; timedMove=0; }
if(REC_DATA>0) { steptimer=(int)REC_DATA*1000; timedMove=1; }
if(REC_DATA<0) { steptimer=(int)fabs((float)REC_DATA)*2000; timedMove=1; }
}
//***********************************************************************************
**
// Drive Motor West with optional: timeout (REC_DATA>0) [s]
// steps (REC_DATA<0) [engle]
//***********************************************************************************
**
void DriveWest()
{
Halt();
goE=0;goW=1;
if(REC_DATA==0){ steptimer=0; timedMove=0; }
if(REC_DATA>0) { steptimer=(int)REC_DATA*1000; timedMove=1; }
if(REC_DATA<0) { steptimer=(int)fabs((float)REC_DATA)*2000; timedMove=1; }
}
//***********************************************************************************
**
// Store Satellite Position & Enable Limits
//***********************************************************************************
**
void Storenn()
12. Diseqc x/USALS interface
ZSOLT LEVENTE Page 12
{
}
//***********************************************************************************
**
// Drive Motor to Satellite Position nn
//***********************************************************************************
**
void Gotonn()
{
}
//***********************************************************************************
**
// Drive Motor to Angular Position (°)
//***********************************************************************************
**
void Gotoxx()
{
}
//***********************************************************************************
**
// (Re-) Calculate Satellite Positions
//***********************************************************************************
**
void SetPosns()
{
13. Diseqc x/USALS interface
ZSOLT LEVENTE Page 13
}
//***********************************************************************************
**
// FIRST REPLY FROM SLAVE
//***********************************************************************************
**
void Reply1()
{
}
//***********************************************************************************
**
// SECOND REPLY FROM SLAVE
//***********************************************************************************
**
void Reply2()
{
}
//***********************************************************************************
**
// REQUEST RETRANSMIT TO MASTER
//***********************************************************************************
**
void ReqReTransm()
{
}
14. Diseqc x/USALS interface
ZSOLT LEVENTE Page 14
//***********************************************************************************
**
// GENERAL PROIECT SETUP
//***********************************************************************************
**
void Setup ()
{
goE=goW=0;
//---------------------- i/0 setup
TRISB=0b01000000;
TRISA=0;
//---------------------- intSet
INTCON=0b10100000; // GIE,PEIE,T0IE
//---------------------- counter (T1)
T1CON=0b00000010;
//---------------------- timer (T0)
OPTION=0b00000111; //256presc
//WriteTimer1(64098); // 1ms
}
//***********************************************************************************
**
15. Diseqc x/USALS interface
ZSOLT LEVENTE Page 15
//===================================================================================
=============
// 2012 Jakab Zsolt
// DISEQC 1.2;2.2/USALS compatible interface
// PIC16F628, osc 4 Mhz,
// RB3 - tx
// RA4 - rx
// RB6 - cmdEAST
// RB7 - cmdWest
//
=====================================================================================
==========
#include <htc.h>
#include <stdlib.h>
__CONFIG( WDTDIS & PWRTEN & HS & BOREN & LVPDIS & UNPROTECT );
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#include "usalsHED.h"
#endif
//---------------------------------------------------------------------------------------------
void main(void)
{
unsigned char s=0,z=0,u=0,rec=0;
Setup ();
16. Diseqc x/USALS interface
ZSOLT LEVENTE Page 16
while(1)
{
//-----------------------------rx
rec=DISEQC_REC ();
//-----------------------------
if(rec>0)
{
if(REC_CMD==96)Halt();
if(REC_CMD==104)DriveEast();
if(REC_CMD==105)DriveWest();
}
}
}
//---------------------------------------------------------------------------------------------