Showing posts with label Micro-controller. Show all posts
Showing posts with label Micro-controller. Show all posts

Saturday, January 30, 2016

How to wire the LCD pinouts for the Atmega88p

Above shows the Pinout of where and what the 1x16 LCD Screen is connected to for the Atmega88p LCD code. The pinouts on the LCD screen show the parts of the LCD and the Legend shows where the pinouts of the LCD are connected to the Atmega88p.

Atmega88p code for a 16x1 LCD Screen


The pictures above uses the code below. The LCD screens are 1 by 16  and are split into 2 parts of 8.
Replace the pink XXXXXXXX, with the desired words, but remember, the screen is split in 2 parts.



//#define F_CPU         4000000UL
#include <avr/delay.h>
#include <avr/io.h>

/*LCD function declarations */
void LCD_send_command(unsigned char cmnd);
void LCD_send_data(unsigned char data);
void LCD_init();
void LCD_goto(unsigned char y, unsigned char x);
void LCD_print(char *string);
void LCD_blink();
void LCD_scroll(unsigned char direction);

#define LCD_DATA_PORT PORTB
#define LCD_DATA_DDR   DDRB
#define LCD_DATA_PIN     PINB

#define LCD_CNTRL_PORT           PORTC
#define LCD_CNTRL_DDR DDRC
#define LCD_CNTRL_PIN   PINC

#define LCD_RS_PIN                       0
#define LCD_RW_PIN                     1
#define LCD_ENABLE_PIN            2

int main(void)
{
DDRD =0xFF;
PORTD|=1<<0;
PORTD|=1<<1;
PORTD|=1<<2;
PORTD|=1<<3;
PORTD|=1<<4;
            unsigned char i;

    LCD_init();
            LCD_goto(1,1);
            LCD_print("XXXXXXXX");
            LCD_goto(2,1);
            LCD_print("XXXXXXXX");
      
}

/* This function sends a command 'cmnd' to the LCD module*/
void LCD_send_command(unsigned char cmnd)
{
            LCD_DATA_PORT = cmnd;
            LCD_CNTRL_PORT &= ~(1<<LCD_RW_PIN);
            LCD_CNTRL_PORT &= ~(1<<LCD_RS_PIN);

            LCD_CNTRL_PORT |= (1<<LCD_ENABLE_PIN);
            _delay_us(2);
            LCD_CNTRL_PORT &= ~(1<<LCD_ENABLE_PIN);
            _delay_us(100);
}

/* This function sends the data 'data' to the LCD module*/
void LCD_send_data(unsigned char data)
{
            LCD_DATA_PORT = data;
            LCD_CNTRL_PORT &= ~(1<<LCD_RW_PIN);
            LCD_CNTRL_PORT |= (1<<LCD_RS_PIN);

            LCD_CNTRL_PORT |= (1<<LCD_ENABLE_PIN);
            _delay_us(2);
            LCD_CNTRL_PORT &= ~(1<<LCD_ENABLE_PIN);
            _delay_us(100);
}

void LCD_init()
{
            LCD_CNTRL_DDR = 0xFF;
            LCD_CNTRL_PORT = 0x00;
            LCD_DATA_DDR = 0xFF;
            LCD_DATA_PORT = 0x00;

            _delay_ms(10);
            LCD_send_command(0x38);
            LCD_send_command(0x0C);
            LCD_send_command(0x01);
            _delay_ms(10);
            LCD_send_command(0x06);
}

/* This function moves the cursor the line y column x on the LCD module*/
void LCD_goto(unsigned char y, unsigned char x)
{
            unsigned char firstAddress[] = {0x80,0xC0,0x94,0xD4};

            LCD_send_command(firstAddress[y-1] + x-1);
            _delay_ms(10);          
}

void LCD_print(char *string)
{
            unsigned char i=0;

            while(string[i]!=0)
            {
                        LCD_send_data(string[i]);
                        i++;
            }
}

void LCD_blink()
{
            LCD_send_command(0x08);
            _delay_ms(250);
            LCD_send_command(0x0C);
            _delay_ms(250);
}

void LCD_scroll(unsigned char direction)
{
            if(direction == 0)
                        LCD_send_command(0x18);
            else
                        LCD_send_command(0x1C);

            _delay_ms(500);

}

Thursday, December 31, 2015

Micro-controller mosfet switch/ Led Christmas light flasher

Micro-controller MOSFET switch/ Led Christmas light flasher
 The above circuit is an attachment for any type of microcontroller, but I used it with a homemade atmega88p microcontroller chip. This board/ circuit allows the chip to turn on and off things like led lights acting like solid state relays. This circuit uses 4 IRF 540 n-channel MOSFETs, switching on and off the negative side of the LEDs.

Below shows the pinout of IRF540.


Below shows the Micro-controller controlling LED Lights







Wednesday, July 29, 2015

Led Transistor flasher


This is a circuit that flashes 2 leds back and forth without any ics or micro-controllers. this is a multivibrator circuit which flashes the leds depending on the resistances of R1 and R2, more resistance means slower flashing speed, less resistance means faster flashing speed. You can also change the capacitance of C1 and C2 to also change the flashing speed.\

On the left is the circuit I made that runs on 9 volts and has output wires leading to multiple leds for a flashing sign/signal.