lets get educated

microconHolic

Project : Stopwatch on ATmega16 (AVR)

Atmega16 and atmega8535 have the same characteristic, so this explanation should work for both of them.

I was helping Mrs Sri, she need this for her Thesis. It is a simply program, she just need to make a stopwatch with microcontroller. I use INT0 as timer ON and INT1 as timer OFF. We use LCD to display the time.
crystal clock = 11.0592 MHz, Timer 0.

This is the program================================================
#include

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0×15 ;PORTC
#endasm
#include lcd.h
#include stdio.h
char lcd_buffer[33];
unsigned int count;

// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
count=0;
}

// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
// Place your code here
//TCCR0=0×00;
lcd_gotoxy(0,0);
sprintf(lcd_buffer,”waktu %u ms”,count);
lcd_puts(lcd_buffer);
}

// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
TCNT0=0×53;
count++;

}

void main(void)
{
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=P State2=P State1=T State0=T
PORTD=0x0C;
DDRD=0×00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock scale: 64
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0×03;
TCNT0=0×53;
OCR0=0×00;

// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: On
// INT1 Mode: Rising Edge
// INT2: Off
GICR|=0xC0;
MCUCR=0x0F;
MCUCSR=0×00;
GIFR=0xC0;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0×01;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0×80;
SFIOR=0×00;

// LCD module initialization
lcd_init(16);

// Global enable interrupts
#asm(“sei”)

while (1);
}
=================================================================

How to set up 1 millisecond ?
the key point are : TCCR0=0×03; and TCNT0=0×53;
TCCR0=0×03; that means clock crystal/64, we got 5.78 us for one clock cycle in TCNT0
TCNT0=0×53; that means timer0 will overflow start from 83 (=53 in hexa) to 256, this is the multiplier

timer 0 will count 5.78 us x 173 (256-83) = 999.94 us, it’s almost 1 ms right
after the timer 0 finish the counting, micro will perform the program in the interrupt timer (interrupt [TIM0_OVF] void timer0_ovf_isr(void))

IMPORTANT : don`t open up PIN INT0 & INT1 keep them in low state when there is no signal interrupt.

February 11, 2010 Posted by | ATmega8535 project | 16 Comments

How to download program into Atmega8535 (AVR)

This post will explain about the way to download program into micro (atmega8535 or AVR) using codevisionAVR as compiler and STK500 (AVR USB ISP) as the programmer-this picture below-

u can buy it

the step by step :
1. connect the cable from the programmer to the mcrocontroller connection, turn on power supply
2. plug in the USB cable from the programmer into your computer
3. Choose : My computer, (right click) properties, Hardware, Device Manager, (double click) Unknown Device
4. Install the driver
5. Back again to device manager and see… Which port is the programmer plug in…for example com 3 …..

Now your programmer is ready to use, its time to set the compiler (codevisionAVR)
1. Go to : Setting, programmer
2. Choose : STK500/AVRISP, com …. (remember step no. 5 above)
3. Go to : Project, Configure, After build.
4. Click : Program the chip, OK

DONE

you are ready to download any program. to compile your program F9, to download CTRL+F9

Good Luck !!

thanks to : Gun-gun (@my office) and Ismail (@lab) very helpful

February 10, 2010 Posted by | ATmega8535 project | 20 Comments

an Easy way to understand LCD

I hope this explanation would fit the title.

This post will explain about How to control LCD (model LMB162A) using microcontroller such as AVR. Furthermore, I will add the basic information about LCD that will help you to be more familiar with LCD, especially when u used another micro.

LCD : liquid crystal display
Usually I use LCD model LMB162A (16Characters x 2lines) for electronics research purpose. Please googling it on web (u need the datasheet to be more clear about this LCD). This LCD has a driver on it. So, all we have to do is to understand How the driver works. First, we have to know the hardware and How to set up all the components.

Hardware:
There are 16 PIN in the LCD.
PIN 1 = GND
PIN 2 = +5 Volt
PIN 3 = Voltage variable
PIN 4 = RS (control pin)
PIN 5 = R/W (control pin)
PIN 6 = E (control pin)
PIN 7 = DB0 (data pin)
PIN 8 = DB0 (data pin)
PIN 9 = DB0 (data pin)
PIN 10 = DB0 (data pin)
PIN 11 = DB0 (data pin)
PIN 12 = DB0 (data pin)
PIN 13 = DB0 (data pin)
PIN 14 = DB0 (data pin)
PIN 15 = + 5 Volt
PIN 16 = GND
This is the hardware (take attention to pin 3, u need variable resistor to make variable voltage)

We can divide all those PIN into there main point :
1. POWER : PIN no. 1,2,3,15,16.
1 & 2 stand for Logic ; 3 stand for LCD supply; 15 & 16 stand for back light

2. CONTROL : PIN no. 4,5,6.
4 : RS, Register Selection : 1(High) = data byte , 0(Low) = command byte
5 : R/W, Read/Write : 1(High) = Read operation , 0(Low) = Write operation
6 : E, Enable Signal : High = Read data, H=>L (falling edge) = write data

3. DATA : PIN no.7,8,9,10,11,12,13,14.
there r 2 way to put data on LCD, 4-bit and 8-bit
In 8-bit mode : PIN no.7-14 (DB0-DB7)
In 4-bit mode : PIN no.11-14, (DB4-DB7)
and open all the pin no.7-10 (don`t connect them to ground, just open up,do nothing)

to be continue….

February 9, 2010 Posted by | LCD | Leave a Comment

Menampilkan bilangan desimal ke LCD

thanks to Acuy….it’s really work

untuk menampilkan suatu tampilan ke LCD sebenarnya sangat mudah, apalagi kalau kita menggunakan codewizard nya codevisionAVR. Hanya saja data yang ditampilkan terbatas dalam bentuk integer. NAh… dalam banyak kasus kita membutuhkan tampilan hasil dari suatu rumus tertentu atau hasil dari pembacaan sensor yang terkadang memiliki angka dibelakang koma alias desimal atau float. kalau dipaksakan (dengan cara biasa) maka mikro akan menolak dan akan muncul peringatan memory tidak mencukupi……… sudah pernah dicoba sampai pake ATMEGA64 tapi teuteup aja ga bisa.
Oleh karena itu harus di akalin…. thanks to Acuy again, I know this solution from him.

Ops tapi sebelumnya mungkin harus saya jelaskan dulu seperti apa sih cara nampilin bilangan yang biasa ke LCD
Ok, this is the step :
1. Di codewizard silahkan pilih LCD, tentukan mau di PORT mana LCD dipasang
2. Catat nomor-nomor pin yang harus dihubungkan antara PORT mikro dan PIN LCD
3. Save dan berikut contoh programnya

=======================================================================
#include

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0×15 ;PORTC
#endasm
#include
#include
#include

char lcd_buffer[33];

void main(void)
{

// Timer(s)/Counter(s) Interrupt(s) initialization

// LCD module initialization
lcd_init(16);
lcd_gotoxy(0,0);
lcd_puts(“HAsil pembacaan”);
lcd_gotoxy(0,1);
lcd_puts(“nampilin apaa gitu”);

// Global enable interrupts
#asm(“sei”)

while (1)
{};
}
========================================================================
jadiii penambahannya :
char lcd_buffer[33];
—————————-
lcd_gotoxy(0,0);
lcd_puts(“Hasil pembacaan”);
lcd_gotoxy(0,1);
lcd_puts(“nampilin apaa gitu”);
—————————–

lcd_gotoxy(0,0); artinya menampilkan di baris pertama, kalau mau dibaris kedua ganti jadi (0,1);
silahkan aja dicoba-coba.

kalau mau nampilin suatu nialai dari variabel semisal
unsigned int data;
—-
sprintf(lcd_buffer,”%u”,data);
lcd_puts(lcd_buffer);
——————————

ok, that’s all, simple kan
Nah masalah akan datang kalau nilai yang mau ditampilkan dari variabel data itu float atau desimal
Solusinya kita pakai fmod , termasuk dalam library math.h
saya dah baca di help-nya codevision tapi sungguh tidak help (he..he…), saya lebih ngerti pas liat contoh penggunaannya
intinya fmod akan menyimpan sisa pembagian, berikut contohnya :
misal saya mau nampilkan hasil perhitungan dari 8/3 ke LCD

a=8;
b=3;
c=a/b;
d=fmod(a,b);
e=d*10/b;
f=fmod(d,b);
g=f/b;

tampilkan ke lcd
sprintf(lcd_buffer,”hasilnya %u,%u%”,c,e,g);
lcd_puts(lcd_buffer);

jadi
c = angka pertama
e = angka pertama dibelakang koma
g = angka kedua dibelakang koma

maka di LCD akan tampil : hasilnya 2,66

Selamat mencoba

February 7, 2010 Posted by | LCD | Leave a Comment

   

Follow

Get every new post delivered to your Inbox.