Hi guys,
I am trying to develop an X10 Rf remote controller to control lamp modules (to turn lights and appliances on an off). I want to introduce some delays as shown in the program, but when I try to build it I get some errors "undefined reference to delay ms" and undefined reference to delayus....and also undefined reference to shiftleft .I am new to programming and would really appreciate if someone could help me in this regard.
#include <stm32f10x_lib.h>
#include "x10.h"
/************************************************************************************
*Function name: x10_sendpreamble
*Description: sends 1 for 9msec & 0 for 4.5msec
*Input: None
*Output: None
*Return :None
*****************************************************************************/
void x10_sendpreamble()
{
GPIO_WriteBit(GPIOA, GPIO_Pin_2, Bit_RESET);
delayms(40);/* Delay before start*/
GPIO_WriteBit(GPIOA, GPIO_Pin_2, Bit_SET);
delayms(8);
GPIO_WriteBit(GPIOA, GPIO_Pin_2, Bit_RESET);
delayms(4);
}
void x10_sendbit(int thebit)
{
GPIO_WriteBit(GPIOA, GPIO_Pin_2, Bit_SET);
delayus(400);
GPIO_WriteBit(GPIOA, GPIO_Pin_2, Bit_RESET);
delayus(700);
if(thebit==0)
{
delayus(1100);
}
return;
}
void x10_sendbyte(int thebyte)
{
u8 i;
for (i=0;i<8;i++)
{
x10_sendbit(shift_left(&thebyte,1,0));
}
return;
}
void x10_send(char hc, int unit, int action)
{
int ufcbyte; // unit function code
x10_sendpreamble();
// here we set the house code
if (unit > 8) { hc=0b00000011; } else { hc=0b00000111; }
switch (unit)
{
case 'P': hc=hc|0b11001000; break;
case 'O': hc=hc|0b11011000; break;
case 'N': hc=hc|0b11101000; break;
case 'M': hc=hc|0b11111000; break;
case 'L': hc=hc|0b00101000; break;
case 'K': hc=hc|0b00111000; break;
case 'J': hc=hc|0b00001000; break;
case 'I': hc=hc|0b00011000; break;
case 'H': hc=hc|0b01001000; break;
case 'G': hc=hc|0b01011000; break;
case 'F': hc=hc|0b01101000; break;
case 'E': hc=hc|0b01111000; break;
case 'D': hc=hc|0b10101000; break;
case 'C': hc=hc|0b10111000; break;
case 'B': hc=hc|0b10001000; break;
case 'A':
default: hc=hc|0b10011000; break;
}
x10_sendbyte(hc); x10_sendbyte(~hc); // send the house code and its inverse
// here, we set the unit and function code bits
switch (action) { // need to support dim/bright
case 0: { ufcbyte=0b10000111; break; } // on
case 1: { ufcbyte=0b10100111; break; } // off
default: { ufcbyte=0b11111111; break; } // A1on
}
switch (unit) {
case 8: { ufcbyte=ufcbyte|0b00000000; break; }
case 7: { ufcbyte=ufcbyte|0b00010000; break; }
case 6: { ufcbyte=ufcbyte|0b00001000; break; }
case 5: { ufcbyte=ufcbyte|0b00011000; break; }
case 4: { ufcbyte=ufcbyte|0b01000000; break; }
case 3: { ufcbyte=ufcbyte|0b01010000; break; }
case 2: { ufcbyte=ufcbyte|0b01001000; break; }
case 1: default: { ufcbyte=ufcbyte|0b01011000; break; }
}
x10_sendbyte(ufcbyte); x10_sendbyte(~ufcbyte); // send the unit/function code and inverse
x10_sendbit(1); // gratuitous 1 at the end…
return;
}