Showing posts with label Mikro. Show all posts
Showing posts with label Mikro. Show all posts

Sunday, June 28, 2009

7 Segment Interface

untuk membuat rangkaian 7 segment yang akan kita hubungkan ke sebuah mikrokontroler melalui port I/O kita memerlukan beberapa 7 segment. sebuah 7 segmnet akan mewakili 1 digit.

Serial RTC

RTC (real time clock) merupakan IC yang dapat menyimpan setting waktu. sebagai contoh saat sebuah komputer di matikan selama 3 hari misalnya. maka saat kita ON kan lagi waktu dalam komputer masih menunjukkan waktu saat itu, waktu tidak mengalami kelambatan walaupun selama 3 hari tanpa sumber tegangan.
RTC meruapakan IC yang dapat mempertahan setting waktu. Ada 2 macam tipe IC RTC yaitu serial dan pararel. Untu schema di atas merupakan serial RTC. Agar waktunya sesuai standar maka diperlukan xtal eksternal 32.768 kHz. Saat supply utama OFF IC akan dapat suplly dari Baterai sehingga setting waktu tetap jalan.
IC ini haruslah terkoneksi ke sebuah mokrokontroler.

Wednesday, April 15, 2009

ISP Downloader

Untuk mendownload program assembly dari komputer ke mikrokontroler (AVR, MCS-51) dapat memanfaatkan pararel port pada komputer.

Friday, March 20, 2009

RTC 8051


Rangkaian di atas menggunakan RTC DS1307 yang memiliki 8 pin. Untuk mengetahui fungsi setiap pin silahkan lihat dataseet. DS1307 memerlukan clock tersendiri seperti gambar. Rangkaian di atas hanya menunjukkan koneksi antara 8051 dengan DS1307 sedangkan output (tampilan) bisa dibuata dengan 7 segmen atau LCD, untuk port outputnya sesuai program yang kita buat.

untuk contoh program bisa saya kirim lewat e-mail (gratis)

Sunday, March 8, 2009

Serial Downloader AVR

Untuk membuat downloader AVR mikrokontroler kebanyakan kita masih menggunakan pararel port (LPT) kecuali beli jadi. Tetapi komputer sekarang sudah tidak menyediakan lagi port pararel, yang lagi tren adalah USB (USB downloader akan kita bahas pada posting berikuitnya). Paling tidak port pararel masih ada pada komputer maupun laptop.

Sebenarnya dari segi biaya dan kemudahan membuat port pararel lebih muda kok. Berikut rangkaiannya:





Cara membuatnya lihat step-step berikut:
Untuk mikrokontrolernya seperti terlihat pada gambar:
Gimana cukup jelas kan
Dari: electronic diy.com


Wednesday, February 4, 2009

LCD DAN KEYPAD



program yang digunakan :
---------------------------

;* Description: Test program with AT90S2313 AVR RISC Processor,
;* LCD display using 4-wire interface and 4x4 keypad.
;*
;* Writed at: 27-05-2003
;* Target: AT 90s2313
;* Author: tom
;*
;* Home page: electronicindonesia.blogspot.com
;*
;* LCD rs pin connected to PD6
;* LCD r/w pin connected to PD5
;* LCD e pin connected to PD4
;* D4-D7 FROM LCD IS CONNECTED TO PORTD PD0-PD3
;* The 4x4 keypad is conected to PortB pins (PB0-PB7)
;* PB0,PB1,PB2,PB3 inputs, PB4,PB5,PB6,PB7 outputs
;*
;*
;*
;***************************************************************************

.include "2313def.inc" ;Define chip particulars


;***** Global register variables
.def wreg =R16 ;General use working register
.def timeout =R17 ;Timeout value passed to subroutine
.def lcdstat =R18 ;LCD busy/wait status
.def longtime=R19 ;Long timer for powerup
.def temp =R20
.def test =R21 ;test register
.def monades =R22
.def dekades =R23

;***** Other equates
.equ lcdrs =PD6 ;LCD rs pin connected to PD6
.equ lcdrw =PD5 ;LCD r/w pin connected to PD5
.equ lcde =PD4 ;LCD e pin connected to PD4
.equ line1 =0x80 ;1ç ãñáììç ôïõ LCD
.equ line2 =0xC0 ;2ç ãñáììç ôïõ LCD
.equ col1 =0b11101111 ;Êïëüíá 1
.equ col2 =0b11011111 ;Êïëüíá 1
.equ col3 =0b10111111 ;Êïëüíá 1
.equ col4 =0b01111111 ;Êïëüíá 1



; Main program entry point on reset

reset:


ldi temp,RAMEND
out SPL,temp ;Init Stack Pointer


rcall longdelay ;Delay some time
ldi temp,0b11110000 ;PB0,1,2,3 inputs, PB4,5,6,7 outputs
out DDRB,temp
ldi temp,0b00001111 ;enable internal pull-ups on PB0-PB4
out PORTB,temp

rcall lcdinit ;Initialize LCD module
again: ldi monades,$30
ldi dekades,$30
rcall lcdclr ;Clear the LCD
ldi wreg,line1 ;Set address to line 1
rcall lcdcmd
ldi ZH,high(2*message1) ;Type the message1
ldi ZL,low(2*message1) ;to the LCD
rcall loadbyte

ldi wreg,line2 ;Set address to line 2
rcall lcdcmd
ldi ZH,high(2*message2) ;Type the message2
ldi ZL,low(2*message2) ;to the LCD
rcall loadbyte

;=========================================================================
; Check all keys (1-16).
; The comments from the first 4 keys are the same with all other keys.
;=========================================================================
check_keys:
ldi temp,col1 ;Enable column1
out PORTB,temp
rcall delay

sbic PINB,PB0 ; Pressed key No1 ?
rjmp key2 ; if Not, check next key
ldi monades,$31 ; if yes...
rjmp disp_no_of_key ; goto type it to LCD

key2: sbic PINB,PB1 ; Pressed key No2 ?
rjmp key3 ; if Not, check next key
ldi monades,$32 ; if yes...
rjmp disp_no_of_key ; goto type it to LCD

key3: sbic PINB,PB2 ; Pressed key No3 ?
rjmp key4 ; if Not, check next key
ldi monades,$33 ; if yes...
rjmp disp_no_of_key ; goto type it to LCD

key4: sbic PINB,PB3 ; Pressed key No4 ?
rjmp key5 ; if Not, check next key
ldi monades,$34 ; if yes...
rjmp disp_no_of_key ; goto type it to LCD

key5: ldi temp,col2 ; Disable the first column...
out PORTB,temp ; and enable the second
rcall delay

sbic PINB,PB0 ; Pressed key No5 ?
rjmp key6 ; if Not...
ldi monades,$35 ;
rjmp disp_no_of_key

key6: sbic PINB,PB1 ; Pressed key No6 ?
rjmp key7 ; if Not...
ldi monades,$36 ;
rjmp disp_no_of_key

key7: sbic PINB,PB2 ; Pressed key No7 ?
rjmp key8 ; if Not...
ldi monades,$37 ;
rjmp disp_no_of_key

key8: sbic PINB,PB3 ; Pressed key No8 ?
rjmp key9 ; if Not...
ldi monades,$38 ;
rjmp disp_no_of_key

key9: ldi temp,col3 ;
out PORTB,temp
rcall delay

sbic PINB,PB0 ; Pressed key No9 ?
rjmp key10 ; if Not...
ldi monades,$39 ;
rjmp disp_no_of_key

key10: sbic PINB,PB1 ; Pressed key No10 ?
rjmp key11 ; if Not...
ldi monades,$30 ;
ldi dekades,$31
rjmp disp_no_of_key

key11: sbic PINB,PB2 ; Pressed key No11 ?
rjmp key12 ; if Not...
ldi monades,$31 ;
ldi dekades,$31
rjmp disp_no_of_key

key12: sbic PINB,PB3 ; Pressed key No12 ?
rjmp key13 ; if Not...
ldi monades,$32 ;
ldi dekades,$31
rjmp disp_no_of_key

key13: ldi temp,col4 ;
out PORTB,temp
rcall delay

sbic PINB,PB0 ; Pressed key No13 ?
rjmp key14 ; if Not...
ldi monades,$33 ;
ldi dekades,$31
rjmp disp_no_of_key

key14: sbic PINB,PB1 ; Pressed key No14 ?
rjmp key15 ; if Not...
ldi monades,$34 ;
ldi dekades,$31
rjmp disp_no_of_key

key15: sbic PINB,PB2 ; Pressed key No15 ?
rjmp key16 ; if Not...
ldi monades,$35 ;
ldi dekades,$31
rjmp disp_no_of_key

key16: sbic PINB,PB3 ; Pressed key No16 ?
rjmp check_keys ; if Not...
ldi monades,$36 ;
ldi dekades,$31
rjmp disp_no_of_key

;=========================================================================
; Here is typed the message3 ,message4, dekades and monades to LCD
;=========================================================================
disp_no_of_key:
rcall lcdclr ; Clear the LCD
ldi wreg,line1 ; Set address to line 1
rcall lcdcmd
ldi ZH,high(2*message3) ; Load high part of byte address into ZH
ldi ZL,low(2*message3) ; Load low part of byte address into ZL
rcall loadbyte

ldi wreg,line2 ; Set address to line 2
rcall lcdcmd
ldi ZH,high(2*message4) ; Load high part of byte address into ZH
ldi ZL,low(2*message4) ; Load low part of byte address into ZL
rcall loadbyte
mov wreg,dekades
rcall lcdput
mov wreg,monades
rcall lcdput
rcall longdelay ;Wait some time
rjmp again

;=========================================================================
; Clear entire LCD and delay for a bit
;=========================================================================
lcdclr:
ldi wreg,1 ;Clear LCD command
rcall lcdcmd
ldi timeout,256 ;Delay 15 mS for clear command
rcall delay
ret


;=========================================================================
; Initialize LCD module
;=========================================================================

lcdinit:

ldi wreg,0 ;Setup port pins
out PORTD,wreg ;Pull all pins low
ldi wreg,0xff ;All pins are outputs
out DDRD,wreg
ldi timeout,256 ;Wait at least 15 mS at power up
rcall delay
ldi wreg,3 ;Function set
out PORTD,wreg
sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
ldi timeout,65 ;Wait at least 4.1 mS
rcall delay
ldi wreg,3 ;Function set
out PORTD,wreg
sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
ldi timeout,2 ;Wait at least 100 uS
rcall delay
ldi wreg,3 ;Function set
out PORTD,wreg
sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
ldi wreg,2 ;Function set, 4 line interface
out PORTD,wreg
sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
ldi wreg,0b11110000 ;Make 4 data lines inputs
out DDRD,wreg

; At this point, the normal 4 wire command routine can be used

ldi wreg,0b00100000 ;Function set, 4 wire, 2 line, 5x7 font
rcall lcdcmd
ldi wreg,0b00001100 ;Display on, cursor off, blink off
rcall lcdcmd
ldi wreg,0b00000110 ;Address increment, no scrolling
rcall lcdcmd

ret

; Wait for LCD to go unbusy
lcdwait:

ldi wreg,0xF0 ;Make 4 data lines inputs
out DDRD,wreg
sbi PORTD,lcdrw ;Set r/w pin to read
cbi PORTD,lcdrs ;Set register select to command
waitloop:

sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
in lcdstat,PIND ;Read busy flag
sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
sbrc lcdstat,3 ;Loop until done
rjmp waitloop

ret

; Send command in wreg to LCD
lcdcmd:

mov test,wreg
rcall lcdwait
ldi wreg,0xFF
out DDRD,wreg
mov wreg,test
mov test,wreg
swap wreg
andi wreg,0X0F
out portD,wreg
sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
mov wreg,test
andi wreg,0x0F ;Strip off upper bits
out PORTD,wreg ;Put on port
sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
ldi wreg,0xF0 ;Make 4 data lines inputs
out DDRD,wreg
ret

; Send character data in wreg to LCD
lcdput:
mov test,wreg ;Save character
rcall lcdwait ;Wait for LCD to be ready
ldi wreg,0xFF ;Make all port D pins outputs
out DDRD,wreg
mov wreg,test ;Get character back
mov test,wreg ;Save another copy
swap wreg ;Get upper nibble
andi wreg,0x0F ;Strip off upper bits
out PORTD,wreg ;Put on port
sbi PORTD,lcdrs ;Register select set for data

sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
mov wreg,test ;Recall character
andi wreg,0x0F ;Strip off upper bits
out PORTD,wreg ;Put on port
sbi PORTD,lcdrs ;Register select set for data

sbi PORTD,lcde ;Toggle enable line
cbi PORTD,lcde
ldi wreg,0xF0 ;Make 4 data lines inputs
out DDRD,wreg
ret

longdelay:
ldi longtime,180 ;
ldi timeout,256 ;
puwait:
rcall delay
dec longtime
brne puwait
ret

;***** Delay n*64 microseconds using timer 0, delay time passed in timeout
delay:

ldi test,64
cagain: dec test
brne cagain
dec timeout
brne delay
ret

;=========================================================================
loadbyte:
;=========================================================================
lpm ; Load byte from program memory into r0

tst r0 ; Check if we've reached the end of the message
breq return ; If so, quit

mov wreg,r0
rcall lcdput ; Echo received char

adiw ZL,1 ; Increase Z registers
rjmp loadbyte

return: ret ;return
;=========================================================================


message1:
.db "Press any key",0
message2:
.db "please (1-16)",0
message3:
.db "You pressed",0
message4:
.db "key:",0

Template by : kendhin x-template.blogspot.com