Hello all,
This is an RF project need to convert the C-code to Osho .....
PIC16f628A
anyone please, thanx in advance.
RX-CODE:
TX-CODE:
This is an RF project need to convert the C-code to Osho .....
PIC16f628A
anyone please, thanx in advance.
RX-CODE:
C:
#define _LEGACY_HEADERS
//#include <htc.h>
#include <xc.h>
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
#pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
/********** VERIABLE **********/
/* Data bit */
#define Bit0 0x01 //Data bit 0
#define Bit1 0x02 //Data bit 1
#define Bit2 0x04 //Data bit 2
#define Bit3 0x08 //Data bit 3
#define Bit4 0x10 //Data bit 4
#define Bit5 0x20 //Data bit 5
#define Bit6 0x40 //Data bit 6
#define Bit7 0x80 //Data bit 7
#define TIME 10000 //10 Sec
#define CR 0x0d
#define LF 0x0a
#define ON 0
#define OFF 1
/* PORTA REGISTER */
/* PORTB REGISTER */
#define SOUNDEN RB4 //Sound Enable
#define LEDSTT RB5 //LED STATUS
static bit Alarmflag; //
static bit Recflag;
unsigned char Recbuff[12]; // RX Buffer
unsigned char bank1 *Recptr;//Receive Pointer
unsigned char Delay3;
unsigned char Delay4; //Learning Remote
unsigned int Delay1;
unsigned int Delay2;
union dat_long
{
unsigned char byte[4];
unsigned long word;
};
union dat_long Dat_long;
/********** initialize **********/
void init (void)
{
CMCON = 0b00000111; //PORTA DIGITAL I/O
PORTA = 0xff; //SETUP PORT
PORTB = 0b11000111;
TRISA = 0b11111111;
TRISB = 0b11000111;
OPTION &= 0b01111111; //PORTB INTERNAL FULL UP ON
Recflag = 0;
Alarmflag = 0;
Delay1 = 0;
Delay2 = 0;
Delay3 = 0;
Delay4 = 0;
SOUNDEN = OFF;
}
void init_timer2() //8 Bits
{
//4MHz/4MC = 1 Meg
//25*10*4 = 1000
PR2 = 24;
T2CON = 0b01001101; //PRE = 1:10,POST = 1:4
PEIE = 1; //
GIE = 1;
TMR2IE = 1; //Enable Timer2 Overflow Interrupt
}
/********** Function usart **********/
void usart (void){
unsigned char a;
CLRWDT();
RCSTA = 0b10010000;
TXSTA = 0b00000000;
SPBRG = 103; //SPBRG = 207 -->300 BPS
//SPBRG = 103 -->600 BPS
//SPBRG = 51 -->1200 BPS
//SPBRG = 25 -->2400 BPS
RCIE = 1;
a = RCREG;
a = RCREG;
a = RCREG;
ei();
}
void clrbuf()
{
unsigned char i;
for(i=0;i<=9;i++)
Recbuff [i] = 0;
}
static void interrupt isr(void)
{
unsigned char temp;
//----------------USART Interrupt------------------
if ((RCIE) && (RCIF))
{
if (OERR){
CREN = 0;
CREN = 1;
}
if (RCREG == ':')
{
temp = RCREG;
Recptr = &Recbuff[0]; //Receiver Pointer @Recbuf[0]
Recflag = 1;
}
else
if (RCREG == CR)
{
RCIE = 0;
if((Recbuff[0]=='C')&&(Recbuff[1]=='M')&&(Recbuff[2]=='D')&&(Recbuff[3]=='0')&&(Recbuff[4]=='1'))
{
clrbuf();
Alarmflag = 1;
SOUNDEN = ON;
Delay2 = TIME;
}
RCIE = 1;
}
else
if (Recflag)
{
*Recptr = RCREG; //
if (Recptr < &Recbuff[10]) //
Recptr++;
}
}
else
//----------------Timer1 Interrupt------------------
//Every 0.001 Sec
if((TMR2IE)&&(TMR2IF)) //Over Flow
{
TMR2IF = 0; //Clear Over flow
if(Delay2>0)
Delay2--;
if((Delay2==0)&&(Alarmflag))
SOUNDEN = OFF;
Delay1++;
if(Delay1>=1000)
Delay1 = 0;
if(Delay1<=50)
LEDSTT = 1;
else
LEDSTT = 0;
}
}
/********** Function DELAY time **********/
void dmsec (unsigned int Count)
{ unsigned char i;
while (Count)
{
for (i=0;i<=128;i++);
Count--;
// CLRWDT();
}
}
//***************************************************//
// MAIN //
//***************************************************//
void main (void)
{
init();
usart();
init_timer2();
while(1)
{
/*
if(Rfflag)
{
Rfflag = 0;
}
*/
}
}
TX-CODE:
C:
#define _LEGACY_HEADERS
#include <xc.h>
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
#pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
/********** VERIABLE **********/
/* Data bit */
#define Bit0 0x01 //Data bit 0
#define Bit1 0x02 //Data bit 1
#define Bit2 0x04 //Data bit 2
#define Bit3 0x08 //Data bit 3
#define Bit4 0x10 //Data bit 4
#define Bit5 0x20 //Data bit 5
#define Bit6 0x40 //Data bit 6
#define Bit7 0x80 //Data bit 7
#define Freebyte 0x00
#define Startb ':'
#define CR 0x0d
#define LF 0x0a
#define ID 678 //MAX 99999999
/* PORTA REGISTER */
#define TX_VCC RA2
/* PORTB REGISTER */
#define SW_OFF RB7
#define SW_ON RB6
#define LED RB4
static bit Onflag;
static bit Offflag;
unsigned char Idbuff[8];
/********** initialize **********/
void init (void)
{
CMCON = 0b00000111; //PORTA DIGITAL I/O
PORTA = 0x11111011; //SETUP PORT
PORTB = 0b11001111;
TX_VCC = 0;
TRISA = 0b00111011;
TRISB = 0b11001111;
OPTION &= 0b01111111; //PORTB INTERNAL FULL UP ON
RBIE = 1;
Onflag = 0;
Offflag = 0;
ei();
}
/********** service routine interrupt **********/
static void interrupt isr(void)
{
if((RBIE)&&(RBIF))
{
if(!SW_ON)
Onflag = 1;
if(!SW_OFF)
Offflag = 1;
RBIF = 0;
}
}
/********** Function usart **********/
void usart (void){
RCSTA = 0b10010000; //SPEN=1,CREN=1
//Asynchronous serial port enable
//continuous receive
TXSTA = 0b00100000; //Low speed TXEN = 1, SYNC = 0
//Transmit enable
SPBRG = 103; //SPBRG = 207 -->300 BPS
//SPBRG = 103 -->600 BPS
//SPBRG = 50 -->1200 BPS
//SPBRG = 25 -->2400 BPS
TXIF = 1;
}
/********** Function sbyte **********/
void sbyte (unsigned char dat)
{
while (!TXIF); //WAIT FOR SEND OK
TXREG = dat;
}
void sempty ()
{
while (!TRMT);
}
/********** Function DELAY time **********/
void dmsec (unsigned int Count)
{ unsigned char i;
while (Count)
{
for (i=0;i<=128;i++);
Count--;
// CLRWDT();
}
}
void send_on() //Send On
{
TX_VCC = 1;
LED = 1;
sbyte(Freebyte); sbyte(Freebyte);
sbyte(Startb);
sbyte('C'); //
sbyte('M'); //
sbyte('D'); //
sbyte('0'); //
sbyte('1'); //
sbyte(CR);
sbyte(LF);
sempty();
TX_VCC = 0;
dmsec(50);
LED = 0;
Onflag = 0;
}
void send_off() //Send On
{
TX_VCC = 1;
LED = 1;
sbyte(Freebyte); sbyte(Freebyte);
sbyte(Startb);
sbyte('C'); //
sbyte('M'); //
sbyte('D'); //
sbyte('0'); //
sbyte('2'); //
sbyte(CR);
sbyte(LF);
sempty();
TX_VCC = 0;
dmsec(50);
LED = 0;
Onflag = 0;
}
/********** main **********/
void main (void)
{
unsigned char ii;
init();
usart();
//init_timer1();
while(1)
{
send_on();
dmsec(100);
}
}
Last edited: