ARM7 Tutorial in c
GPIO
ckt. Dig of the above code
More tutorials on ARM coming soon...
Embedded system with AVR
Embedded programming using ATMEGA 16:Here i am going to tell you about the embedded programming using Atmega16 microcontroller with c language.This is very easy.
In the below your seeing the Pin out of Atmega-16.
To start C programming language on Atmel AVR Microcontroller you need to download these following tools:
My first AVR Project
To create your first AVR project go to Start -> All Programs -> Atmel AVR Tools -> AVR Studio 4, this will launch the AVR Studio 4 application and the Welcome to AVR Studio 4 form appear, click on the New Project button and it will show the Create new project screen as follow:
On Project Type choose AVR GCC, enter myfirstc for the project name and you could also change the project location directory as you like, then click on the Next>> button, you will be asked for debugging platform on the following screen:
Choose AVR Simulator for debug platform and ATmega16 for the device, then click on the Finish button. This will create all the necessary files and directories needed for this project. Now the AVR Studio 4 IDE is ready and display the empty myfirstc.c file.
Enter or cut and paste this source program bellow to the program code windows:
First, you need some setup. Go to menu setup->interface setup and make setting like this.
Select the serial port in which your programmer is connected. Beware there may be more that 1 available com port showing there and usually only one is available outside the PC the rest are internal and may be connected to your modem. So make sure you have selected a port that is connected to your programmer and not to your modem. Next, go to set up->calibration. Now you are done. Connect the programmer you have made to you PCs serial port or parallel port and connect its ISP connector to the target you have made. Switch on the target. The software is self explanatory with easy to use GUI in the top tool bar there is a selection for type of chip you want to program. Select “AVR Micro” and select the type of Micro( like ATmega16) in box next to it.
FEATURES:
Direction control of individual bits
Separate control of output set and clear
All I/O default to inputs after reset
ARM 7 has two port named as Port 0 and Port 1. Each port can be used as I/P or O/P. Port 0 has 0-31 pins and Port1 has 16-31 pins.
Each Port can be used as GPIO(general purpose I/p and O/p) or As SFR(Special Function).
1. To use it as GPIO we have to set some register.
PINSEL0----it must be 0 to use LSB of port 0 as GPIO(0-15)
PINSEL1---it must be 0 to use MSB of port 0 as GPIO(16-31)
PINSEL2---it must be 0 to use Port 1 as GPIO
2. To set the direction of any Port as I/P or O/P we have to SET and
CLR a Register named as IODIR
1---set as o/p
0---set as i/p
Example:
IO0DIR=0x00000000; // it means port 0 will act as i/p
IO1DIR=0x000000ff; // it means lower 8 bit of port 1 will act as o/p
3. Now Lets Put some data on register. For that we are using two register IOSET and IOCLR. As its name shows it can set and clear particular data bit.
Example:
IO0SET=0x00000001; //it means 0th bit of Port 0 will be set
IO0CLR=0x00000001; //it means 0th bit of Port 0 will be cleared
Power supply ckt of ARM
ARM requires two power supply one is for CPU(+1.6 to 1.95v) and other is for I/O(+3 to 3.6v)
Now it’s Time for a “HELLO WORLD Program”
//this is written in Keil uvision v 4.0 and for LPC2124(ARM7 TDMI)//
// I am going to blink a LED, whose anode is connected to Port0.0
#include lpc21xx.h
int main()
{
int i;
PINSEL0=0x00000000; //port 0 set to GPIO
IO0DIR=0x00000001; // 0th bit of port 0 will act as o/p
while(1)
{
IO0SET=0x00000001; // LED will glow
for(i=0;i<100000;i++); //to create some delay
IO0CLR-0x000000001; //Led will off
for(i=0;i<100000;i++); //to create some delay
}
How to check Input in ARM7
To check input in ARM, we can use a register named as IOPIN. This register can also be used to set output.
Example:
if((IO0PIN&0x00000001) = = 0x00000001);
{
//this statement will execute when the 0th bit of port0 will be high
}
IO0PIN=0x00000002;// it means 1st bit of Port 0 set to High (As output)
Lets Do a I/P and O/P program
#include lpc21xx.h
int main()
{
PINSEL0=0;
IO0DIR=0x000000ff;
PINSEL2=0x00000000;
IO1DIR=0x00000000;
if((0x00010000&IO1PIN)==0x00000000) //giving input at p1.16
{
IO0PIN=0x00000001; // anode of led is connected to 0th bit of Port0
}
else
{
IO0PIN=0x00000000;
}
}
ckt. Dig of the above code
Embedded system with AVR
Embedded programming using ATMEGA 16:Here i am going to tell you about the embedded programming using Atmega16 microcontroller with c language.This is very easy.
In the below your seeing the Pin out of Atmega-16.
To start C programming language on Atmel AVR Microcontroller you need to download these following tools:
- Down load the latest Atmel AVR Studio which provide you with the complete IDE (integrated development environment) for managing project, program editing, compiling, debugging and downloader for all Atmel AVR Microcontroller series.
- The Atmel AVR Studio only provide you with native microcontroller language (assembler), so you need to down load the WinAVR Project which provide you with AVR GCC (GNU C Compiler for AVR Microcontroller) base compiler and library for window environment. This AVR GCC is fully integrated and supported by Atmel AVR Studio.
To create your first AVR project go to Start -> All Programs -> Atmel AVR Tools -> AVR Studio 4, this will launch the AVR Studio 4 application and the Welcome to AVR Studio 4 form appear, click on the New Project button and it will show the Create new project screen as follow:
On Project Type choose AVR GCC, enter myfirstc for the project name and you could also change the project location directory as you like, then click on the Next>> button, you will be asked for debugging platform on the following screen:
Choose AVR Simulator for debug platform and ATmega16 for the device, then click on the Finish button. This will create all the necessary files and directories needed for this project. Now the AVR Studio 4 IDE is ready and display the empty myfirstc.c file.
Enter or cut and paste this source program bellow to the program code windows:
/***************************************************************************
#include
#include
void Wait()
{
uint8_t i=0;
for(;i<23;i++)
_delay_loop_2(0);
}
void main()
{
//Set PORTC0 as output
DDRB=0b00000001;
while(1)
{
//Set Port D=High(+5v)
PORTB=0xff; // in hexadecimal
Wait();
//Set Port D=Low(GND)
PORTB&=0b00000000; // in binary it is 0x00 in hexadecimal
Wait();
}
}
The program start with the standard comment (all the statement start with
double slash is consider as comment in standard C syntax) that give the
information about the program, version and compiler version,etc. The next two
include statement tell the C compiler to include the AVR microcontroller specific libraryand the delay library when compiling the program.Inside the main
program, first we instruct the AVR microcontroller (i.e. avr/io.h) to enable
it’s 8 bit PORT-D input/output port for output by setting the data direction
register (DDRB) on PORT-B to 0x01 that is 0b00000001 in binary. Next inside the while(1) loops statement (it’s mean we loop continuously) we
simple instruct the AVR microcontroller to turn on and off all it’s 8 bit
PORT-D by assigning the value 0xFF (on) and 0×00 (off) to the PORT-B register
(PORTB). The 100 millisecond delay is put there so our eye could catch the
process, otherwise the process is so fast that we see the port is always on.
Building the HEX Files:-
Once you have written the code Just press F7 key of your key board to compile and
generate the HEX code.....
Downloading the HEX code to Microcontroller:-
To download the code you need a programmer ckt..in the below i am giving a
ckt dig of a parallel port(BSD) programmer which is very low cost
programmer...you need some simple wire and connectors to make it.
if you have not have a PC then you can make your USB programmer which
is little costlier...You can click here to learn how to make
USB programmer...
Once you have made the programmer connect it to your computer and
download the programmer using the following steps....
Programming Using PonyProg.
This is the programmer we made in the previous tutorial. Its use is simple. Start Ponyprog, you will get a screen similar to this.Fig - Ponyprog main window. |
Fig - Ponyprog Setup |
- Select the hex file you want to program using the File->Open Program(FLASH) file.
- Command->Erase.
- Command->Write Flash
- Command->Verify Program(FLASH)
- If every thing is correct, your MCU is programmed successfully.
- Disconnect programmer from the Target and switch it off.





No comments:
Post a Comment