Monday, January 16, 2012
Friday, January 13, 2012
§AVR Touch Pad
This is my AVR Touch-Pad. After completing touch screen
interfacing with AVR I decided to make a touch-pad where I can write, draw and
erase and finally I completed something like as I want. A resistive touch
screen is mounted upon GLCD. There is three Touch-buttons for pencil, brush and
eraser named A, B and C.
~Pratyush
Gehlot
Tuesday, January 3, 2012
§5x7 AVR Pong Game
Pong is one of the first computer
game that ever created, this simple "tennis like" game features two
paddles and a ball, the goal is to defeat your opponent by being the first one
to gain10 point, a player gets a point once the opponent misses a ball. The
game can be played with two human players, or one player against a computer
controlled paddle. The game was originally developed by Allan Alcorn and
released in 1972 by Atari corporations. Soon, Pong became a huge success, and
became the first commercially successful game, On 1975, Atari release a home
edition of Pong (the first version was played on Arcade machines) which sold
150,000 units. Today, the Pong Game is considered to be the game which started
the video games industry, as it proved that the video games market can produce
significant revenues.
http://www.ponggame.org/
In this post I am going to explain
5x7 pong game using AVR. In my previous post I will explain working and
interfacing of 5x7 LED matrix display with AVR. Now this time we will use it
again to make PONG!!!.Ok!! Let’s make:
Circuit
Diagram:
Making
Steps:
Step1:
First of all you have to make this
circuit. You can make this circuit on zero PCB or download PCB layout from here
which I design in “PCB Wizard”.
If you want to design this PCB at
home then Read this post:
Note: You can download PCB layout in PDF. If you are going to design this PCB then open the
PDF and set its zoom to 75.1% and then take it's current view print.
Step2: Paste all the components and jumper
wires:
Step2: Make 5x7 LED matrix display. To
know how to make this and its working. read this post:
Step4: Connect LED matrix display with PCB
using burg-strip.
Step5: Complete Setup
Step6: Connect 12Volt adapter for power
supply
How
to Play:
After powering the circuit, press “game”
(right hand side UP) button to play game and press “Alfa”( (right hand side
DOWN ) to see alphabets and numbers.
Initially it will display two paddles
and a ball. This is a two player game. Each player has two buttons for up and
down. Press the button to move paddles up and down. Ball bounces between two paddles.You have to defeat your opponent two times to win the game. If you miss the
ball you lost a point and opponent gets one point. LED will indicate one point,
the first who gain two points will win the game.
Downloads:
PCB
layout, circuit diagram, compiled .hex file for Atmega8.
Video:
~Pratyush Gehlot
Monday, January 2, 2012
§Embedded ‘C’ Programming Notes – Part2
Read First:
9. Current Sinking and Current Sourcing:
we
can configure MCU as current sinking as well as current sinking, see the figure, we can connect LED to MCU in two ways.
Current sourcing: Vcc
supplied by MCU, MCU provides current to drive LED.
Current sinking: MCU
sinking the current.
Note: The maximum current
sourcing rating of AVR MCU is about 250ma, if our circuit needs more then 250ma
then we must configure MCU as current sink.
10. Inputs to microcontroller: MCU
works on TTL logic if the output of the corresponding circuit is in TTL level
then we can directly connect the output of the circuit with an input pin of our
controller. If the circuit has output which is not in TTL level then we need to
adjust the level of hardware for ex. Using optocouplers, voltage divider, Level
converter etc.
At 5
volt : 0 to 1v = LOW and 3.5v to 5v = High
11. Reading Input from Registers:
input = PINX; //Copies the status of the
input pins from port X
EX: Let’s take input at PB0 and output at PA0.
TASK: LED should glow when input=1.
int main()
{
DDRA=(1 << PA0);//PA0 is output pin
DDRB&=~(1 << PB0);//PB0 is input pin
PORTA=0; //initially LED is off
while(1)
{
uint8_t input;
input=PINB;
if(input)
PORTA=(1 << PA0);
else
PORTA &=~(1 << PA0);
}
}
This
code is correct and has no error but the output will not be seen as we want,
LED will fluctuate continuously. Because we leave input pin open. When we will
not give any input then it will take random value from environment.
Means this input pin is floating.
When
we configure any pin as input, it does not drive the port pin and the port pin
is said to be floating. A floating pin can be taken to any voltage level by
even a weak signal or EMI.
In
order to take an input or connect other floating components (like - switch) a
pull up is required to make the clear logic level on the pin.
Active Low configuration (PULL UP):
Used to drag the level at open pin on logic ‘1’(High).
Active High configuration (PULL DOWN):
Used to drag the level at open pin on logic ‘0’(Low).
The
value of pull-up resistance should be between 4k ohm to 10k ohm.10k ohm is
common value for this.AVR have software switchable internal pull-Up resistors,
whih can be used instead of external components.
To
activate internal pull-up we have to write PORTB=(1<<PB0);
The correct way to take Input to Microcontroller:
int main()
{
DDRA=(1 << PA0);//PA0 is
input
DDRB &=~(1 << PB0); //PB0 is output
PORTA=0; //initially LED is off
PORTB=(1 << PB0); //Enable Internal Pull-Up
while(1)
{
char input;
input=PINB;
if(!input)
PORTA=(1<<PA0);
else
PORTA&=~(1<<PA0);
}
}
12. Input with Masking the Bits: In
the last code we took separate ports for input and output but if our controller
pins is limited then we have to adjust input and outputs in same ports or if we take multiple inputs in the same port then if we check the status of one
input pin then the other input pin status will interfere with this.
We
can query the status of the input bits by reading the entire contents of the
register and hide the bits which state is not of interest. Hiding unwanted bits
is known as masking.
Let’s take an example:
PB1
and PB2 is input pins and PB0 is output pin.
TASK: LED should glow by
pressing S1 and goes off by pressing S2
Code :
int main()
{
DDRB=(1<<PB0);//
PB0 is output rest is input
PORTB=(1<<PB1)|(1<<PB2);
//PULL Ups
PORTB&=~(1<<PB0);//initially LED is
off
uint8_t input;
while(1)
{
input
= (PINB & ((1<<PB1)|(1<<PB2)) ); //
masking of input pins
//or input=(PINB & 0x06);
switch(input)
{
case 0x04: PORTB&=~(1<<PB0); //when S1 is
pressed LED will glow
case 0x02 : PORTB|=(1<<PB0); //when S2 is pressed LED will goes off
}
}
}
13. Read a bit: The AVR
library (avr libc) gives two functions to the inquiry of an individual bit of a
register.
This
function examines whether a bit is set, if the bit is set, a non-zero value is
returned.
This
function examines whether a bit is reset, if the bit is reset, a non-zero value
is returned.
Ex: if(bit_is_set(PINB,0)) Ex:
if(bit_is_clear(PINB,0))
{ {
Do this Do this
}
}
14. Waiting for a specific state:
Loop_until_bit_is_set(PINB,0)
OR
while( ! (PINB & (1 << PB0) )
);
Loop_until_bit_is_clear(PINB,0)
OR
while( PINB & (1 << PB0) );
~Pratyush
Gehlot
Subscribe to:
Posts (Atom)
-
Hello Friends, After a long delay, now again I am ready to post some interesting projects. Here I am sharing automatic R...
-
Hello Friends, LED Matrix displays are very popular for displaying messages you can see them in everywhere in your daily routine. Fo...
-
Hello, Here i am going to explain a very simple well known and Interesting project "Line Tracking Robot". Line tr...
PID Controlled Self balancing Robot using ESP8266 and MPU6050
This ROBOT is made using ESP8266 Node MCU and MPU6050 accelerometer. Motor used here is normal gear motor of 150 rpm with TB6612FNG motor dr...