My Circuits

GETTING A 5V DC OUTPUT FROM AN AC SOURCE
 This circuit shows how to obtain a 5V dc from a 240V ac supply (50Hz). The 7805 is used to regulate the rectified output (the four diodes form the full bridge rectifier) to obtain a voltage of 5V. A voltage of 12V or 9V can also be obtained using 7812 and 7809 respectively.

GENERATING A SQUARE WAVE USING 8051
/*
Description: Generating a square wave using Timer0
             for 8051 microcontroller

Written by:     Victor
*/
           

#include <reg51.h>

sbit pin = P2^0;
sbit pin2 = P2^1;
void T0Delay(void);

void main()
{
    P1 = 0x00;       //initialize port 1
    pin = 0;

    while(1)       //loop forever
    {
        pin = 1;
        T0Delay();        //Timer0 is used to generate delay
        pin = 0;
        T0Delay();
    }
}

void T0Delay()
{
    TMOD = 0x01;          //timer0 mode 1
    TH0 = 0xDB;
    TL0 = 0xFE;
    TR0 = 1;              //enable timer0 run bit
    while(TF0 == 0);      //wait here while flag remains 0
    TR0 = 0;
    TF0 = 0;
}   


                                                              Output
                                                                

7-SEGMENT DISPLAY USING 8051
/*
Description: The code is just a practice work, when a button
is pressed, an led lights up, the 7-segment display indicates
the number of leds that lite up

Written by: Victor

Note: The code could be modified and length reduced to
reduce the amount of ram consumed
*/

#include <reg51.h>

#define leds P2
#define segment P3

sbit button1 = P1^0;
sbit button2 = P1^1;
sbit button3 = P1^2;
sbit button4 = P1^3;
sbit button5 = P1^4;
sbit button6 = P1^5;
sbit button7 = P1^6;

void Delay(void);

unsigned char display[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; // display no between 0-9

unsigned char j = 0;    //initialize

void main()
{
    segment = 0x00;             //initialize
    leds = 0x00;
   
    if(button1 == 0)                 //loop forever
    {
        leds = 0x01;
        segment =  display[1];           //output the numbers
        Delay();                       //Delay for one second
    }
    else if(button2 == 0)
    {
        leds = 0x24;
        segment =  display[2];           //output the numbers
        Delay();                       //Delay for one second
    }
    else if(button3 == 0)
    {
        leds = 0x25;
        segment =  display[3];           //output the numbers
        Delay();                       //Delay for one second
    }
    else if(button4 == 0)
    {
        leds = 0x5A;
        segment =  display[4];           //output the numbers
        Delay();                       //Delay for one second
    }
    else if(button5 == 0)
    {
        leds = 0x5B;
        segment =  display[5];           //output the numbers
        Delay();                       //Delay for one second
    }
    else if(button6 == 0)
    {
        leds = 0x7E;
        segment =  display[6];           //output the numbers
        Delay();                       //Delay for one second
    }
    else if(button7 == 0)
    {
        leds = 0x7F;
        segment =  display[7];           //output the numbers
        Delay();                       //Delay for one second
    }

}

void Delay(void)
{
    unsigned int x;
    for(x=0;x<33000;x++);
}

/*
    This display numbers 0-9 on a 7-segment
    display

    Written by: Victor
*/

#include <reg51.h>

#define segment P2        // Assign identifier (segment) to Port 2   

void Delay(void);

unsigned char display[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned char j = 0;    //initialize

void main()
{
    segment = 0x00;             //initialize

    while(1)                 //loop forever
    {
        segment =  display[j];           //output the numbers
        Delay();                       //Delay for one second
        j++;                           //increment by 1;
        if(j > 9) j = 0;
    }
}

void Delay(void)                     
{
    unsigned int x;
    for(x=0; x<33000; x++);                //one second delay loop
}           



CHASING LED PROGRAMMING IN C USING KEIL UVISION FOR 8051

/*
Description:    Eight Leds are connected to Port of the 8051
                microcontroller, an led lights up, delays for about 1 sec
                switches off, and the next led switches on, the loop repeats
                itself forever

Written by:     Victor
*/

#include <reg51.h>
#define LEDS P2

void Delay_ms(unsigned int);

void main()
{
    unsigned char j = 1;     // initialize value for j

    while(1)
    {
        LEDS = j;               // assign the value for j to P2
        Delay_ms(100);           //Delay about 1 sec...not too accurate though
        j = j << 1;               // shift value left
        if(j == 0) j = 1;       //if value exceeds 128 (decimal) initialize j
    }
}

void Delay_ms(unsigned int itime)
{
    unsigned int i,x;

    for(i = 0;i<itime;i++)
        for(x=0; x<1275; x++);
}



6V CONSTANT VOLTAGE CHARGER
This is a 6v constant voltage charger, the source is a solar panel (12V), LM317 is used as the adjustable voltage regulator, and the potentiometer is used in regulating the output voltage.