Deteksi Nomor HP Otomatis dg Mikrokontroller

Posted in Microcontroller on 12 March, 2008 by as

Beberapa waktu yg lalu ketika membuat proyek antarmuka HP dg mikrokontroler, ada masalah bagaimana mambuat agar uC (AT 89S52) dapat mendeteksi berbagai macam nomor telepon? Di Indonesia ada beberapa operator : Indosat, Telkomsel, XL, dll dengan produk kartu SIM yg bermacam sehingga menyebabkan jumlah nomor telepon yang diterima pun bermacam-macam. Lalu apakah proyek komunikasi antar alat dan HP hanya 1 buah nomoe tujuan saja? Nggak lucu dong kalo nggak bisa detek macem2 nomor… Ya kalo pake PC enak, lha ini pake mikro seri S lagi.

Akhirnya ada beberapa method (mungkin) tapi salah satu demikian (barangkali langsung sc saja,,,,,):

;mengecek no hp pengirim

;======================

cek_nohp: ;nomor hp =12 (tidak pake kode negara 081…)

mov r7,70h

cjne r7,#’D’,cek_nohp1

mov r3,#18

mov r1,#71h

ret

cek_nohp1: ;nohp =10

mov r7,6eh

cjne r7,#’B’,cek_nohp2

mov r3,#16

mov r1,#6fh

ret

cek_nohp2: ;nohp =11 ( three,flexi)

mov r7,6eh

cjne r7,#’C’,cek_nohp3

mov r3,#16

mov r1,#6fh

ret

cek_nohp3: ;nohp =13

mov r7,70h

cjne r7,#’E’,cek_nohp4

mov r3,#18

mov r1,#71h

ret

cek_nohp4: ;nohp =9

mov r7,6ch

cjne r7,#’A’,del_sms

mov r3,#14

mov r1,#6dh

ret

Dari sekian nomor kemungkinan kan cuma 9 sampe 13 (ada yg 14 nggak ya?) Lha disini kita memanafaatkan fungsi R1 sebagai Register index sehingga nomor telpon bisa dideteksi di RAM ke berapa… then program untuk mengambil nomor HP yg dimaksud? Here we are….

tx_no_hp:

clr a

mov a,@r1

call tx

dec r1

djnz r3,tx_no_hp

ret

tx:

clr es

mov sbuf,a

jnb ti,$

clr ti

setb es

ret

Pertanyaannya pengalamatan RAMnya seperti apa?

; INTERUPSI SERIAL

data_in:

jb RI,data_in1

clr TI

reti

data_in1:

push psw

push acc

mov a,sbuf

mov 74h,73h

mov 73h,72h

mov 72h,71h

…….

…….

……

mov 42h,41h

mov 41h,40h

mov 40h,A

clr ri

pop acc

pop psw

reti

Mudah2 ini kebaca… bukan sekedar sampah blog… he he he.

Salam.

Advertisements

2X16 LCD LMB 126 Programming on 8051 Microcontroller

Posted in Microcontroller on 28 November, 2007 by as

Most LCD programmed in 8 bit configuration. Moreover LCD put on equipment that show the value of measurement, i.e. temperature, voltage, current, etc. There are a lot of tutorial show steps how to configure out in order to LCD on. But each LCD has  own characteristic. The best way to decide the function of each pin is just check out the serial number of LCD. Get its pdf files, then it has to compatible with the hardware.

I ever made a mistake when I did not check the function each pin. It caused a lot of tutorial of LCD programming in 8051 microcontroller use the HD44780 series, meanwhile I bought the LMB 162 A. It has most different from the function of B+, ground and data, Huh I break it down. I just wasted my 6 USD, I though…

Okay, actually these will show to programmed the LMB 126 A using 8 bit microcontroller. I used ATMEL 89S52 as my microcontroller, but it also compatible with 8051 language programming. In the figure bellow, I used 8 bit data (pin 7 till 16) connect to port 2 microcontroller. Pin number 4 is port 1.3 then pin number 5 is port 1.4.

 micro-LCD interfacing

Base from the LCD Characteristic, the software has to follow the rule bellow in order to the LCD can be adjusted and showed the characters we want. Time delay rutine can be found easily. Just googling, find it, how simple it is.

 

flowchart LCD

After we know about the sequence software (above), let start to write the code, compile it then upload it to chip. I my self have my code, here bellow:

rs equ 94h;p1.4

en equ 93h;p1.3;Send_DataLCD EQU 280H

lcall init_lcd;

mov dptr,#message1;

lcall sendmessage_lcd;

lcall write_in_lower;

mov dptr,#message2;

lcall sendmessage_lcd;

lcall delay_1_s;

lcall delay_1_s;

lcall delay_1_s; 

lcall delay_1_s;

call clr_lcd ;

mov dptr,#message3;

lcall sendmessage_lcd;

lcall write_in_lower;

mov dptr,#message4;

lcall sendmessage_lcd;

lcall delay_1_s;

lcall delay_1_s; ;

lcall delay_1_s;

lcall delay_1_s;

;;;;LCD NEED RUTINE OF ;;;;;;;;;

;===========================|

Init_LCD:; 

Mov A,#00111000b ; Send 38H

Lcall Send_Perintah; 

call delay_200_us; 

Mov A,#00001110b;send 0eh

Lcall Send_Perintah ; 

call delay_200_us; 

Mov A,#01H;send 01H

Lcall Send_Perintah ; 

call Delay_50_ms;  

Mov A,#00000110b;Mode Incr. Address

Lcall Send_Perintah; 

call delay_200_us; 

Ret ; 

;======================================|

clr_lcd: ; 

Mov A,#00000001b;Mode Increament Address 

Lcall Send_Perintah;

call delay_50_ms;

Ret

write_in_lower:

Mov A,#0c0h;

Lcall Send_Perintah;

call delay_200_us;

ret

;=====================================|

sendMessage_LCD:

LoopSendMessage_LCD:

Mov A,#00H;

Movc A,@A+Dptr;

Cjne A,#0FH,Send_LCD;

Ret

Send_LCD:

Lcall Send_Character

Inc Dptr;

Ajmp LoopSendMessage_LCD

;============ =========================|

Send_perintah:

clr rs

Lcall Send_DataLCD

call delay_200_us

Ret

Send_Character:

setb rs

Lcall Send_DataLCD

call delay_200_us

Ret

Send_DataLCD:

Mov p2,A

Nop

Acall Pulse_Clock

Ret

Pulse_Clock:

setb en

nop

clr en

ret

Send_Character:

                                setb rs

                                Lcall Send_DataLCD

                                call delay_200_us

                                Ret

Send_DataLCD:                

                                Mov p2,A

                                Nop

                                Acall Pulse_Clock

                                Ret

Pulse_Clock:

                                setb en

                                nop

                                clr en    

                                ret

……………………….

;MESSAGE TO LCD

message1:

db ‘DATA MONITORING ‘,0fh

message2:

db ‘ACCESSED BY SMS ‘,0fh

message3:

db ‘    amansubanjar’,0fh

message4:

db ‘      @gmail.com’,0fh

 

;RUTINE OF DELAY

;==============

delay_50_ms:

mov tmod,#21h

mov th0,#02ch

mov tl0,#012h

setb tcon.4 ; tcon.4 = tr0

count_50_ms:

jbc tf0,finish_50_ms

jbc tcon.5,finish_50_ms ; tcon.5 = tf0

sjmp count_50_ms

finish_50_ms:

ret

delay_200_us:

mov tmod,#21h

mov th0,#0ffh

mov tl0,#027h

setb tcon.4 ; tcon.4 = tr0

count_200_us:

jbc tf0,finish_200_us

jbc tcon.5,finish_200_us ; tcon.5 = tf0

sjmp count_200_us

finish_200_us:

ret

delay_1_s:

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

call delay_50_ms

ret

;===========================| 

 

end

AT89S Atmel single chip microcontroller

Posted in Microcontroller on 28 November, 2007 by as

Several years ago Atmel produced S Series from their 8 bit microcontroller. In the my college its popular enough, and I think so, just when I browse for “89S52 application”, I found a lot of article. I thought that this chip only famous in some region or country, but I wrong.

For the detail of its chip, you’d better go ATMEL’s site then see the 89S52 specification. I used it to finish my work a few months ago.

How about the prices? Cheap enough! It sold only no more than 2 USD, so if we want to built any programmable control, I though that it was the right answer. But why not AVR? For my own reason, the “internet help” support 8051 language is more instant than we’d solved with AVR. But the most important things that we should know is the need and function. It need the downloader to transfer the binary code program we’d written.

How could I build the downloader? I found the easiest schematic made by someone. And also I have the uploader software from Pakistanis. I have alot of references about the schematic diagram , PCB layout, but this is the simple and simple one.

For editor you can use programmers notepad, save the file in .asm or .h51 format. Here the problems come. You should have a converter from asembler to hexadesimal. Remember that hexafiles you have, must compatible with 8051 family. I use berin to convert my .h51 to hex. Then you have .hex file, with no error of course. Upload it to chip.

ASCII to PDU (Septet Encoding) amansubanjar@gmail.com

Posted in Microcontroller on 28 November, 2007 by as

Its not a little bit hard make an ASCII to PDU converter in Delphi or VB. They have unlimited Register, or even the AVR Series from ATMEL (31 registers). But hows the program in AT89S52 or 8051/8052 family? They just have 8 registers. If all registers free, then these registers still 8, it’ll decrease as we use it.

For this case I use RAM (AT89S52 has 30H – 79H addressable RAM). Some characters stored in RAM then we’ just write the formula.

PDU itself used as a standard message in SMS (Short Message Service) allover the mobile phone. Although most cellular phone could be controlled with text(ASCII) format, the process of sending or receiving always in PDU. Also if we want to make some stuff in 8bit microcontroller, will it be written by ASCII? Yah, the first time we also declare the text we want to convert , (8bit ASCII of course) then by some manipulation bit, it converted to 7 bit, then the result still converted again in hexadecimal (8bit) as microprocessor standard data.

Okay here the illustration:

8bit (ASCII character standard formatted in Hexa)——-> 7bit PDU Standard——->Hexadecimal, the final result.

And here the source Code:

$mod51

d1 equ 30h;kode ascii data 1 ch 1

d2 equ 31h

d3 equ 32h

d4 equ 33h

d5 equ 34h

d6 equ 35h

d7 equ 36h

d8 equ 37h

d9 equ 38h

d10 equ 39h

d11 equ 3ah

d12 equ 3bh

a1 equ 76h;kode ascii data 1 ch 1

a2 equ 77h

a3 equ 78h

a4 equ 79h

a5 equ 7ah

a6 equ 7bh

a7 equ 7ch

a8 equ 7dh

;SEPTET PROCESSING

send_pdu_start:

push psw

push acc

mov a1,d1

mov a2,d2

mov a3,d3

mov a4,#’ ‘

mov a5,d4

mov a6,d5

mov a7,d6

mov a8,#’0′

call septet_encoding1

mov a1,#’ ‘

mov a2,d7

mov a3,d8

mov a4,d9

mov a5,#’ ‘

mov a6,d10

mov a7,d11

mov a8,d12

call septet_encoding1

exit:

pop acc

pop psw

ret

septet_encoding1:

mov a,a1

mov b,#00000001b

call divab

mov a,a2

mov b,#10000000b

call mulab

mov a,a2

mov b,#00000010b

call divab

mov a,a3

mov b,#01000000b

call mulab

mov a,a3

mov b,#00000100b

call divab

mov a,a4

mov b,#00100000b

call mulab

mov a,a4

mov b,#00001000b

call divab

mov a,a5

mov b,#00010000b

call mulab

mov a,a5

mov b,#00010000b

call divab

mov a,a6

mov b,#00001000b

call mulab

mov a,a6

mov b,#00100000b

call divab

mov a,a7

mov b,#00000100b

call mulab

mov a,a7

mov b,#01000000b

call divab

mov a,a8

mov b,#00000010b

call mulab

ret

divab:

div ab

mov r5,a

ret

mulab:

mul ab

add a,r5

send:

acall hexascii2

acall send1

mov a,b

acall send1

ret

send1:

call tx;mov sbuf,a

;jnb ti,$

;clr ti

ret

hexascii2:

push acc

acall hexascii1

mov b,a

pop acc

swap a

acall hexascii1

ret

hexascii1:

anl a,#0fh;

cjne a,#10,lookcarry;acc a=10 dan carry 0 -> not number

lookcarry:

jnc not_number

add a,#30h

ret

not_number:

add a,#37h

ret

;=====

Then how will we sure that our code is true? Meanwhile the ascii code is sent by serial. Just test it use with hyperterminal, insert the code with the time delay more than 5 seconds, it used for unplug and plug the serial (com1) connector. If we still need more than 5 seconds, add it again with the time we can stand enough,….I did with the 3 seconds delay time. Its enough for me.

Happy coding…..It shoulda worked out.