Click here to Skip to main content
13,054,615 members (60,046 online)
Click here to Skip to main content
Add your own
alternative version


41 bookmarked
Posted 3 Feb 2010

Remote control based on c8051 with 433MHz radio modules

, 3 Feb 2010
Rate this:
Please Sign up or sign in to vote.
Remote control based on c8051 with 433MHz radio modules.


This article is about the very well known RF modules TX433 and RX433 that (or similar) can be found almost in every electronics shop, and a pair of them costs ~15 bucks.


Using the Silabs C8051F321 microcontroller.


I searched the internet for a 'radio remote control' with more than 8 buttons, but found none. So I decided to program one myself. At first, it seemed an easy task as I have programmed microcontrollers before.

See my other articles on Silabs c8051:

Luckily, I got the idea for this task from reading some other examples:

The problem was to find a solution to the UART communication protocol for radio communication. You need to know a way to read and write to UART in C, that is different than Keil and MCU-s like Silabs ones. The problem is finding a solution not to echo back when reading UART signals. To read UART signals, you must use low-level functions (_getkey) and use interrupts to signal timers that control IO-s.

// SFR Paged version of _getkey
char _getkey ()  {
   char c;
   while (!RI0);  //wait UART receive interrupt to trigger
   c = SBUF0;     //read char from UART
   RI0 = 0;       //signal recieve ready 
   return (c);

At first, I got nothing but garbage from the hypertrminal. Then, I decided to use the other USB-to-Serial cable, and it worked. It has reversed polarity (UART signals are inverted compared to the RS232 signals). One solution to this is to use MAX232 or a transistor to the reverse polarity - I chose the last method.

This is the result:


Large pictures are available here: RX1, RX2, TX.

My mission is to use more than 8 buttons, which is the usual count of buttons in modules like thes, for example: Wellmann catalogue (VM118). The buttons count is limited due to the manufactured controllers-encryption/decryption modules chips limitations. This restriction can be overridden by writing receive-transmission codes yourself. To achieve this goal, I used the well-known Silabs MCU-s C8051F321, but with small modifications, it can used with many other Silabs chips as well.

The transmitting-receiving distance can have a range up to ~50m when applying 15cm antennas. In my case, I used a UART 2400 baud rate. The maximum is 4800bps. But as explained in many places in the internet, and from testing the modules, the recommended connection speed would be 2400bps for better noise/distance ratio.

Many modules are sold and used at the maximum baud rate for a small distance ~10 meters or so, and that's even with antennas. I find that insufficient.

So first, I looked at an example code here: Running TX433 and RX433 RF modules with AVR microcontrollers. It explains the radio packets structure basics (protocol) for these modules:

  1. Sending packet sync - it may be any character
  2. Sending address
  3. Sending a control (verification) byte
  4. ---------------

  5. Sending a carriage return character '13' or '\r'
  6. Waiting for a few ms ~ 10ms
  7. If a button is pressed: the same procedure is repeated again

Receiver waits for synchronization characters (I made that 'SW' for abbreviation, e.g., switch) because the receiver reads a lot of noise while waiting (and we do not want false triggering). After that:

  1. Reads address bits (two bits, e.g., '00' or '21')
  2. Reads a control byte character
  3. Compares the control byte to the address, and if they match, triggers address port to high level
  4. Waits ~100ms and switches all ports to low again (port pulse switching)
  5. If another signal is read before timeout occurs, switches that new port high and old off

Basically, all relays are switched off while no button is pressed.

The purpose of this module is to control the crane movements of the vehicle that moves the garbage containers. (You can't find any of the modified code in modules bought from a shop). In those, you don't need to worry about interferences with other remotes in range.


To read UART pulses with serial port (COM port), you must invert the polarity of signals with transistors or using MAX232. Without reversing the polarity, it is possible to gain connection and also get the device to work, but it will lack the possibility to read signals with the hyperterminal. That means no debug facility. To debug the program, I used a USB-to-Serial adapter like the USB - UART interface in 'Counter based c8051' and read signals with the Silabs debug adapter, for which the firmware was updated. Also, to read, I use my USB terminal 'usbhidio3.exe'.


Hardware schematics:

To update firmware and debug, use Silabs 'Toolstick Base Adapter':



Using the code

The code for the microcontroller is written within Silabs IDE 3.61.00 and compiled with the Keil compiler ver. 8.17. If any button is pressed, a signal like 'SW01b\r' is written to the UART of c8051F321 and the TX433 module sends a code to the receiver RX433. Accordingly, the receiver decodes and lights the LED of that channel (or pulses a relay - if it's connected to the matching port output of the microcontroller).

Here is the basic Tx main module:

void main (void) 

   PCA0MD &= ~0x40;       // WDTE = 0 (clear watchdog timer 
   Timer0_Init ();            // Initialize the Timer0 enable)

   PORT_Init();               // Initialize Port I/O
   SYSCLK_Init ();            // Initialize Oscillator

   EA = 1;                    // Enable global interrupts
//LED =0;
   while (1)
                printf ("SW00a%c",13);
                printf ("SW01b%c",13);
                printf ("SW02c%c",13);
            if(SW03==0) {
                printf ("SW03d%c",13);
                printf ("SW06g%c",13);
            if(SW07==0) {
                printf ("SW07h%c",13);
            if(SW10==0) {
                printf ("SW10k%c",13);
            if(SW11==0) {
                printf ("SW11l%c",13);
            if(SW12==0) {
                printf ("SW12m%c",13);
            if(SW13==0) {
                printf ("SW13n%c",13);
            if(SW14==0) {
                printf ("SW14o%c",13);
            if(SW15==0) {
                printf ("SW15p%c",13);
            if(SW16==0) {
                printf ("SW16q%c",13);
            if(SW17==0) {
                printf ("SW17r%c",13);
            if(SW20==0) {
                printf ("SW20u%c",13);
            if(SW21==0) {
                printf ("SW21v%c",13);
            //if(SW22==0) printf (" SW22w\n");
            if(SW23 == 0) {
                printf ("SW23x%c",13);
        //printf ("\nSW%ca",cOut);
                if(bSwitch == 1){
                    bSwitch= 0;
                    LED = 1;
        }//end of IF LED=0;
    }//end while

The receiver tst_gets module behaves like this:

void tst_gets (void) {

//char c; // temporary char

int i = 2; // temporary int
unsigned long temp_amplitude;
unsigned char chksum;

LED = 0;
    while( _getkey() != 'S' ); // ignore all characters until
    if(_getkey() == 'W')
        LED = 1;
        temp_amplitude = hex2char();
        chksum = _getkey();
        //printf("NR:%ld: %c - %bd\r", temp_amplitude, chksum,chksum-97);
        if(temp_amplitude == chksum-97)
            //printf ("EQ\r");
                if (temp_amplitude < 10) {
                //temp_amplitude = temp_amplitude;
                    P0 = SINE_TABLE[temp_amplitude];
                } else if (temp_amplitude < 20) {
                    temp_amplitude -= 10;
                    P1 = SINE_TABLE[temp_amplitude];
                } else if (temp_amplitude < 30) {
                    temp_amplitude -= 20;
                    P2 = SINE_TABLE[temp_amplitude];
                }//temp_amplitude < 10    
            counter = 0;
        }//if(temp_amplitude == chksum-97)

Software links:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Estonia Estonia
No Biography provided

You may also be interested in...


Comments and Discussions

Question433MHz with Respberry Pin
Syed Javed20-Nov-16 5:47
memberSyed Javed20-Nov-16 5:47 
Questionrf433 and tx 433 Pin
Member 864021612-Feb-12 2:26
memberMember 864021612-Feb-12 2:26 
AnswerRe: rf433 and tx 433 Pin
ingvar814-Feb-12 10:11
memberingvar814-Feb-12 10:11 
QuestionHelp Pin
truthz0317-Nov-11 9:33
membertruthz0317-Nov-11 9:33 
AnswerRe: Help Pin
ingvar818-Nov-11 11:25
memberingvar818-Nov-11 11:25 
GeneralMy vote of 2 Pin
DennisAT15-Feb-10 23:19
memberDennisAT15-Feb-10 23:19 
GeneralRe: My vote of 2 Pin
Abu Mami16-Feb-10 3:09
memberAbu Mami16-Feb-10 3:09 
GeneralDeadBug Contruction well done Pin
leestudley8-Feb-10 12:57
memberleestudley8-Feb-10 12:57 
GeneralGood Article Pin
Just someone else4-Feb-10 21:26
memberJust someone else4-Feb-10 21:26 
GeneralI just love this sh*t! Pin
Abu Mami4-Feb-10 3:25
memberAbu Mami4-Feb-10 3:25 
GeneralNice! Pin
mtode3-Feb-10 23:04
membermtode3-Feb-10 23:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 4 Feb 2010
Article Copyright 2010 by ingvar8
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid