Sunday, November 27, 2011

5- PORT SYSTEM


 Atmega16, avr, blinking led, input, output, port, port configuration, port system, porta, portb, portc, portd, register, tri-state
Port is the edge of data transportation, so that you can send you data through them . Atmega16 has 4 8-bit ports _ PortA , PortB , PortC , PortD _ you can configure them as output or input .
application :
for blinking an LED : you first configure them as output
if you connect them a "button" you will configure them as Input
Ports has three function registers :
( Registers are a place of SRAM , used to configure system)
avr,  port ,  , tri-state , port system , Atmega16,  porta , portb , portc , portd , port configuration , blinking led , output , input , register

///////////////////////////////////////////////////////////
DDRX (X means A or B or C or D):
if DDRX=0xff   ( 0xff is a hexadecimal number with prefix 0x)
 PORTX is configured as output
if DDRX=0x00
PORTX is configured as input (you should set PORTX = 0xff)
//////////////////////////////////////////////////////////
PORTX (X means A or B or C or D)
if PORTX=0xff for output configuration
You send 0xff to PORTX
if PORTX =0xff for input configuration
you used a pullup resistor for input(pullup resistor is a resistor that prevents noise from effecting you input . you should use pullup resistor)
if PORTX=0x00 for input configuration
hi-z state for input
if PORTX=0xff for output configuration
output is 0x00
////////////////////////////////////////////////////////
PINX (X means A or B or C or D)
if you want to get a value from PORT . you should use PINX
//////
notice:
if you configure input as tri-state , your input is like Op-amp inputs with high impedance, so that a small static charge can change the state of input, so you cants predict input
in the future lesson, we will introduce the programming structure
more texts:

Saturday, November 26, 2011

4- Memory sorts

 byte addressable EEPROM, flash, FLASH EEPROM, Programmable lock bits, SRAM, static random access memorystatic random access memory

  1. FLASH EEPROM - in system programmable flash EEPROM
  2. byte addressable EEPROM
  3. SRAM - static random access memory
  4. Programmable lock bits
  • in system programmable flash EEPROM:
a non-volatile memory, you will save your program in

  • byte addressable EEPROM:
its a non-volatile memory , you can edit data during program execution
applications:
  1. logging system malfunctions
  2. saving system settings
  3. electronic lock combinations ,...
atmega16 is equipped with 512 bytes of EEPROM
  • SRAM : Static random access memory
a volatile memory , it will lose data as power get lost
Applications:
  1. IO (input and output) registers
  2. controlling peripheral subsystems
  3. support dynamic data allocation of variables
  4. a location for stack (discussed later)
  • Programmable lock bits
there are six bits of memory that you can program them using programmer . you have the following options
  1. No memory lock features enabled.
  2. No further programming of memory is allowed using parallel or serial programming
    techniques.
  3. No further programming or verification of memory is allowed using parallel or serial
    programming techniques.

Friday, November 25, 2011

3- AVR Programmer : how to make?

avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
AVR Programmer
About AVR Programmer

This simple AVR Programmer will allow you to transfer hex programs to most ATMEL AVR microcontrollers without sacrificing your budget and time. It is more reliable than most other simple AVR programmers available out there and can be built in very short amount of time.
AVR programmer consists of in-circuit serial programmer (dongle) and small pcb with a DIP socket that you can fit your microcontroller and program it quickly.
You may also use this programmer as a stand alone in-circuit serial programmer that can be used to conveniently program AVR microcontrollers without removing them from the target circuit.
Entire AVR programmer has been build with using common parts and fits in the case of the serial connector. The socket pcb has been created to fit a 28-DIP AVR ATmega8 microcontroller, but you can build a socket pcb for any other AVR microcontroller out there. This AVR programmer is compatible with a popular PonyProg software that shows you a status bar of the programming progress.

 AVR In-Circuit Serial Programmer

avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
AVR Programmer's PCB (front) with 9-PIN female RS232 serial connector.
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
AVR Programmer's PCB (back)
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
Fitting AVR Programmer's PCB in RS232 serial case.
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
Finished AVR Programmer with standard 6-PIN ICSP connector.
AVR Socket PCB
Socket PCB has very minimal number of components and is used for programming your desired AVR microcontroller outside of your target circuit. 
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
Socket PCB with 28-DIP AVR ATmega8 microcontroller.
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
There are two connections; ICSP that connects to AVR Programmer, and external +5V supply.
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
 Socket PCB consists of the PCB, 28-DIP socket, 4MHz crystal resonator, or crystal with two 22pF decoupling capacitors, and two header connectors. Two-PIN connector supplies +5V voltage to the AVR microcontroller, and 6-PIN ICSP connects to AVR Programmer dongle.

Supplying microcontroller with external +5V voltage as opposed to taking it directly from computer's serial connection port ensures that the chip is receiving exactly +5V voltage and provides very reliable error free programming. 

avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
Socket PCB for 28-DIP AVR ATmega8 microcontroller.
 +5V voltage supply for AVR chip may be provided from external power supply or even better - directly from USB connection.

 PonyProg

To be able to send hex file from your computer to AVR microcontroller you will need to download and install PonyProg2000. After the installation, the first thing you will need to do is configure PonyProg to work with our AVR Programmer. To do this go to "Setup" menu and select "Interface Setup". The following window will be shown and highlighted areas show you exactly which options should be selected. 
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
In the next step select "AVR micro" and your microcontroller type that you will be programming (ex. ATmega8).
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
At this point PonyProg configuration is complete and we can open hex program with which AVR microcontroller will be flashed. Go to "File" menu, select "Open Program (FLASH) File ...", and point to the hex file to open it up. You should see hex numbers as shown on the screen below. If you haven't connected AVR Programmer dongle to your computer's serial port yet, then now is the time. Make sure that AVR Programmer is physically connected to your AVR microcontroller through Socket PCB or through ICSP 6-PIN connector. Finally click on the highlighted icon "Write Program Memory (FLASH)", or go to "Command" menu and select "Write Program (FLASH)".
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
Click on "Yes" button to confirm the programming.
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
Now sit tight, relax and watch the programming progress on the status bar. PonyProg will program AVR microcontroller and verify if the hex file was transferred without any errors. For your information this process shouldn't really take more than 10 to 30 seconds. This depends on the size of the program that you're trying to flash.
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
After programming is completed "Write successful" window will be shown letting you know that AVR microcontroller has been programmed, and is now ready to be used.
avr, Programmer, atmel,serial programmer,avr programmer,atmega8,ponyprog,flash
 adopted from: electronics-diy.com

Wednesday, November 23, 2011

2- Atmega16 : how to start


 at90s, atmega, attiny, avr, blinking, led, microcontroller, temprature
Atmega16 is a member of mega AVR family . I think its a good start for our purpose . we will start learning with this kind of AVR . you will need : 
1- Atmega16
2- Programmer  
3- Simulator(Proteus)
4- Compiler(Codevision)
5- Led , other devices
6- An AVR Book
1- Atmega16:
has all things that we need for programming . so you will need it in practical purposes
2- Programmer:
if you want to run your code in micro , you should have a programmer to transmit ,code to micro
3- Simulator :
it is really very necessary to simulate a program before we program our chip . because there are many mistakes and logical errors that they will stop or at least harden our goal. if you simulate the program . you will rapidly find and debug your code
Proteus is one of simulators that are needed to simulate, you can download it here
please introduce me if there were better software's
4- Compiler:
we write our code in C(a programming language) ,of course we'll need a compiler to translate our code to assembly and machine language . so I decided to introduce you Codevision .
as i said before:please introduce me ,you the nice friend
5- LED and other devices :
in many times we need a device to show the output . for example if you want to represent a voice you will need a speaker
6-An AVR Book :
for further reading and understanding better , I propose you the books,whether ebook or paper book . Its not necessary but useful . as an example:
Atmel AVR Microcontroller Primer: Programming and Interfacing
download it here for free


for educational purpose you just need simulator and compiler . so you can save money and just buy these two things
don't forget to leave here comments for me

1- AVR : What is MicroController

Microcontroller is a controlling device . it's like a computer without monitor , voice card , ... . but it has software and can control the circuit . for example if I want to make a blinking led or show the temprature .
AVR is a product of Atmel . we have three sorts of avrs.
  1. AtTiny
  2. At90s
  3. AtMega
AtTiny is the smallest of AVR family
AtMega is the most powerfull device in AVR family .
we already use atmega16 a member of AtMega family

please make me suggestions in the comments