Archive for the ‘Logic’ Category

Up/Down Counter Using Logic Gates

Friday, December 5th, 2008

I am a member of this Philippine Electronics Design & Electronics Repair Forum and queries from students for schematics sometimes comes up. A poster asked for a schematic diagram for an UP/Down counter using logic gates on this thread. Here’s my take:
Up/Down Counter Schematic Diagram

Adipex without prescription
Tramadol Side Effects

Download the simulation file here Up/Down Counter Simulation File.

Dallas DS1620 Digital Thermometer/Thermostat Routines

Tuesday, October 28th, 2008

Dallas DS1620 is an integrated circuit that functions as a digital thermometer or thermostat. This device uses a 3-wire interface to read and write data to it. This is added to MCUs that does not have A/D (analog to digital) converters and must rely on external components for temperature monitoring.

The functions below does the reading and writing data to the DS1620:

void DS1620_Write(unsigned char data)
{
    unsigned char i;

    TRIS_DQ = 0;
    TRIS_CLK = 0;
    TRIS_RST = 0;

    CLK = 1;

    for (i=0; i<8; ++i)
    {
        CLK = 0;
        if (data & 1)
        {
            DQ = 1;
        }
        else
        {
            DQ = 0;
        }
        data = data >> 1;
        CLK = 1;
    }
}

unsigned char DS1620_Read(void)
{
    unsigned int t;
    unsigned char i;

    TRIS_DQ = 1;
    TRIS_CLK = 0;
    TRIS_RST = 0;

    CLK = 1;

    t = 0;
    for (i=0; i<9; ++i)
    {
        CLK = 0;
        t = t >> 1;
        if (DQ)
        {
            t = t | 0×100;
        }
        CLK = 1;
    }      

    t = t >> 1;
    return(t & 0xFF);
}

Here is ds1620.c and ds1620.h source codes.

HD44780 LCD Routines in C

Tuesday, October 28th, 2008

This is my implementation of interfacing the HD44780 Hitachi LCD and its variants. This uses 4 bit mode thus lesser wires going to the LCD. The port used on this is PORTB. The lower 4 bits RB0-RB3 are the data nybble. While RS and EN are RB4 and RB5, respectively.

These are some sample functions that are included on this release:

void lcd_clear(void)
{
    set_LCD_RS(0);
    lcd_write(0x01);
    DelayMs(2);
}

void lcd_puts(const char *s)
{
    set_LCD_RS(1);
    while (*s) lcd_write(*s++);
}

void lcd_putch(uchar c)
{
    set_LCD_RS(1);
    lcd_write(c);
}

void lcd_goto(uchar pos)
{
    set_LCD_RS(0);
    lcd_write(0x80|(pos & 0x7F));
}

Click the links lcd.c and lcd.h to download the files.

I2C Routines for PIC Microcontroller

Tuesday, October 28th, 2008

This is a release of my master mode I2C routines for PIC microcontroller to the open source community. This uses bit-banging technique and does not use the hardware SSP peripheral. The routine checks for I2C slave acknowledgment during writing.

Here is an excerpt for writing a byte to to the I2C bus:

unsigned char i2c_write(unsigned char c)
{
    unsigned char i;

    SCL_LOW();
    i=8;
    SDA_TRIS=0;
    do {
        if (c & 0x80) {
            SDA_HIGH();
        } else {
            SDA_LOW();
        }

        //pulse clock
        delay_settle();
        SCL_HIGH();
        delay_clock();
        SCL_LOW();
        delay_clock();
        c<<=1;            //next bit
    } while (--i);

    //get acknowledge
    SDA_HIGH();
    SCL_HIGH();
    delay_half_clock();
    if (SDA) {
        //SDA remains high, not acknowledged
        delay_half_clock();
        SCL_LOW();
        delay_clock();
        return I2C_ERROR_NO_ACK;
    }
    delay_half_clock();
    SCL_LOW();
    delay_clock();
    return I2C_NO_ERROR;
}

Download the full source code i2c.c and i2c.h here.

24-Hour Digital Clock Using Glue Logic Gates

Thursday, March 13th, 2008

I have created a page on this blog featuring a 24-Hour Digital Clock Using Glue Logic Gates. This is an 8 chip design using CMOS/TTL glue logic gates to make a 24-hour running clock.  Made this for learning and fun. Click here here to view it.