Google

Wednesday, August 15, 2007

Upload to micro (Download from PC)

User needs softwares to upload the program to a micro. I recommend you to use PonyProg2000 as downloader software. You can purchase this software by download it from http://www.lancos.com/

Why I recommend this?
1. It's so easily used, you need only 3 steps for the first time.
2. Many devices supported, not only Atmel.
3. You can see the used space and free space on your monitor window. The FF means free space. Based on this, we can conclude the assembler language is the most efficient language rather than both C and BASIC.

Monday, July 9, 2007

Project 2

Project #2
Flip Flop: Turn the LEDs on, then off, then on, then off

Feature used: PortD, Timer, internal interrupt


.include "m8535def.inc"

.org 0
rjmp main
.org 6
rjmp comparematchtim ;int handler for comparematch Timer1

;---------------ISR ;this routine will be executed if comparematch of Timer1 occurs
comparematchtim:
push r16
in r16, SREG ;store content of SREG to SRAM
push r16 ;store content of r16 to SRAM

in r16, PORTD ;copy content of PORTD register to r16
com r16 ;complement it
out PORTD, r16 ;copy back to PORTD register

ldi r16, high(15625)
out OCR1AH, r16
ldi r16, low(15625) ;comparator register OCR1A = 15625 (2 bytes)
out OCR1AL, r16


pop r16
out SREG, r16 ;load back contents to original location
pop r16
reti

;--------------main program
main:
ldi r16, high(RAMEND) ;stack register initialization
out SPH, r16
ldi r16, low(RAMEND)
out SPL, r16

ldi r16, high(15625)
out OCR1AH, r16
ldi r16, low(15625) ;comparator register OCR1A = 15625 (2 bytes)
out OCR1AL, r16
ldi r16, 0b00010000
out TIMSK, r16 ;enable comparematchA Timer1 interrupt

sei ;enable global interrupt

ldi r16, 0b00001011 ;Timer1 CTC mode, prescaler 64
out TCCR1B, r16

ser r16
out DDRD, r16 ;DDRD = $FF, means all of pins at PortD defined as output
out PORTD, r16 ;PORTD = $FF, means each of pins at PortD assigned to out a '1' logic
;the LEDs must be put in high active logic (cathodes connected to GND)

loop: ;this is called loop forever
rjmp loop ;the program will keep run in this address unless an interrupt occurs

Project 1

Project #1
Turn the LEDs on

Feature used: PortD


.include “m8535def.inc” ;the file included depends on kind of micro used

.org 0 ;this is called interrupt vector
rjmp main ;the address 0 means RESET (by power or pin RESET)

main:
ldi r16, low(RAMEND) ;the next 4 rows indicates inisialization of stack register
out SPL, r16
ldi r16, high(RAMEND)
out SPH, r16

ser r16
out DDRD, r16 ;DDRD = $FF, means all of pins at PortD defined as output
out PORTD, r16 ;PORTD = $FF, means each of pins at PortD assigned to out a '1' logic
;the LEDs must be put in high active logic (cathodes connected to GND)

How to begin project?

1.Learn as many as you can about digital electronics, include digital electronics.
2.Acquire your equipments: components, input/output devices, softwares, and also a PC/laptop.
3.Build a minimum system.
4.Write a list of test program, compile and load it into micro.
5.You have finished a simple project



Digital Electronics

There are many terminologies related to the electronics. Voltage, current, resistance, power, energy, wire, bus, component, IC, amplifier, comparator, high logic, low logic, etc. The voltage is the most often talked thing. Generally, we describe the 'logic' as the voltage level. High logic means +5 volt, and called '1', meanwhile low logic means 0 volt (GROUND), and called '0'.

A micro can both source or sink current, therefore the logic of their pins can be '1' and also '0'.

Equipments needed

1.components for minimum system
1.MCU IC (AT90Sxxxx, ATmegaxxxx, ATtinyxx)
2.oscillator system: crystal, ceramics capacitors: 30 pF (2)
3.power system: voltage regulator LM7805, indicator LED, limiting resistor 1 kohm, ceramic capacitor 100 nF.
4.reset system: push button switch, limiting resistor 10 kohm, electrolytic capacitor 10 uF/16 V.
5.several jumpers (made of headers) for port expansion and downloader.
6.several cables needed

2.components for downloader cable
1.a 5-pins data cable (1 meter long)
2.a 5-pins housing
3.a male/female parallel connector (25-pins); to determine using male/female, look at your mainboard, they have to be opposite.
4.optional: limiting resistors 330 ohm

3.input/output devices
1.output devices: LEDs, motors, LCD, PC, electronic systems
2.input devices: switch, PC, optocoupler, electronic systems

4.software
1.operating system: Windows
2..pdf reader: any kind
3.AVRStudio: any version
4.PonyProg2000

5.PC/laptop specification
1.I can't describe here the minimum requirement needed, but based on my experience, a Pentium II based PC with 64 MB RAM is enough to run the microcontroller projects.
2.You will need a PC/laptop which has a parallel port for micro programming, and it is strongly recommended the PC/laptop also has one or two serial port(s) in addition to communicate to the micro.


Test program

There are 3 kinds of the language used to write a program: Assembler language, C language, and also BASIC language. The first one, assembler offers direct instruction to access registers and features in a micro. Nevertheless, the language structure is so simple, therefore makes it so complex. You will see short instructions such as ldi r16, $FF or sei. If you understand them, playing micro is so nice!

The second, C language is higher level than assembler. You can read english words here, such as while, if, unsigned, etc. For newbie, there are many symbols confusing, but it's only need an understanding. C language is known as the language used by many programmers around the world.

And the last, BASIC language. Differ from the others, it offer quick access to the features. Even, we can access a PWM feature in only few rows. The features can be accesses through the config instruction.

This is a test program using assembler language:

;Test program implemented in a ATmega8535 micro
;Turning on the LEDs connected to PortA

.include "m8535def.inc"

.org 0
rjmp main

main:
ldi r16, high(RAMEND)
out SPH, r16
ldi r16, low(RAMEND)
out SPL, r16

ser r16
out DDRA, r16
ldi r16, 0b10101010
out PORTA, r16

;end of program

Wednesday, June 27, 2007

Intro to microcontroller


Microcontroller is a programmable integrated circuit designed for special purposes. A microprocessor is planted inside it, and also several peripherals such as: flash memory, static RAM, EEPROM, Timer/Counter, ADC, Analog Comparator, interrupt system, etc., depends on microcontroller's type.

There are kinds of microcontrollers, produced by many companies: Intel, Atmel Corporation, Harris Semiconductor, Motorola, Microchip Technologies, Maxim, Renesas Technology, and many more. Each of products has its own characteristic.

So, how about shorten our grammar? I’ll call microcontroller as just micro. I think it’s easier to talk.

This weblog talks only micro produced by Atmel Corporation, especially the AVR family. Family of MCS51 is still used, but rarely, rather than AVR family. So, we’ll discuss only AT90Sxxxx, ATmegaxxxx, and ATtinyxx. At the recent, I still use the assembler language, but it’s ok to say in C or BASIC. You can share them for me.

What kind of device we can build based on micro?
The answer is a lot of kind. You can design a digital thermometer, a digital tachometer, a autonomous robot, digital clock, and many more. There are at least 9 classes of micro’s applications:
1. automation
2. display
3. instrumentation
4. power electronics
5. home electronics
6. automotive
7. control system
8. monitoring system
9. PC interface