Translate

Membuat Alat Kendali Dengan NEC REMOTE MP3 / DVD IR Infrared BASCOM AVR

Membuat Alat Kendali Dengan NEC REMOTE MP3 / DVD IR Infrared BASCOM AVR


           Pada kesempatan kali ini saya akan menjelaskan  mengenai bagaimana cara mengakses REMOTE DVD / MP3 Menggunakan mikrokontroller ATMega dan bahasa Basic Bascom AVR. Prinsip kerja alat ini sederhana saja. yaitu menampilkan nilai dari remote ke serial monitor. Alat ini bisa digunakan untuk kendali device lain seperti TV, lampu rumah. kipas angin dan lainnya. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Minimum System




b. IR Infrared Sensor / TSOP




c. REMOTE DVD / MP3




d. Rangkaian RS232





e. Program Bascom AVR

'sumber=http://www.mcselec.com/index.php?option=com_content&task=view&id=223&Itemid=57
$regfile = "m8def.dat"
$crystal = 8000000                                          'Internal RC oscillator 8 MHz
$baud = 9600

Config Pind.2 = Input

'Config Portc.2 = Output

Config Timer0 = Timer , Prescale = 256                      '8000000/256=31250 Hz
Config Int0 = Falling                                       'Interruption on Falling
Stop Timer0
Enable Timer0
Enable Int0
Enable Interrupts
On Timer0 Tikers                                            'work on timer
On Int0 Infrared                                            'work on interruption

Dim Tik As Word                                             'counter of teaks of timer
Dim Byt As Byte                                             'counter accepted bit
Dim Repeat_flag As Bit                                      'flag of repetition
Dim Start_flag As Bit                                       'flag of start condition
Dim Address As Byte                                         'byte of address
Dim Command As Byte                                         'byte of command
Dim Address_1 As Byte                                       'direct byte of address
Dim Command_1 As Byte                                       'direct byte of command
Dim Address_0 As Byte                                       'indirect byte of address
Dim Command_0 As Byte                                       'indirect byte of command
Dim Summa As Word

Cursor Off                                                  'Switch Off cursor
'################################################################################################################


Do                                                          'Main cycle
'Cls
                                                             'Clean LCD
Print Address ; " " ; Command                               'Lcd ADDRESS and COMMAND

'If Command = 8 Then Portc.2 = 1                             'If pressed key "P+" - to include LED

'If Command = 240 Then Portc.2 = 0                           'If pressed key "P-" - to switch off LED

Waitms 200                                                  'Delay 10 en

Loop

End                                                         'End of main cycle

'################################################################################################################

 Tikers:                                                    'work on timer
 Timer0 = 253                                               '31250/(256-253)=10416,66 Hz (96 een)
 Incr Tik
 If Tik >= 1200 Then                                        'if 1200 teaks, have thrown all in source condition
 Tik = 0
 Repeat_flag = 0
 Start_flag = 0
 Address_1 = 0
 Command_1 = 0
 Address_0 = 0
 Command_0 = 0
 Address = 0
 Command = 0
 Stop Timer0
 End If
 Return
'################################################################################################################

 Infrared:                                                  'work on interruption
 Start Timer0

 If Tik >= 139 And Tik < 150 Then                           'if has happenned from 139 before 150 teaks - "START"
  Address = 1
  Repeat_flag = 0
  Start_flag = 1
  Address_1 = 0
  Command_1 = 0
  Address_0 = 0
  Command_0 = 0
 End If

 If Tik >= 116 And Tik < 139 Then                           'if has happenned from 116 before 138 teaks - "REPETITION"
  Address = 2
  Repeat_flag = 1
  Start_flag = 0
 End If

 If Tik >= 22 And Tik < 116 And Start_flag = 1 Then         'if has happenned from 22 before 115 teaks - have taken "1"
 Incr Byt

 If Byt < 9 Then
 Shift Address_1 , Left
     Address_1 = Address_1 + 1
 End If

 If Byt >= 9 And Byt < 17 Then
 Shift Address_0 , Left
     Address_0 = Address_0 + 1
 End If

 If Byt >= 17 And Byt < 25 Then
 Shift Command_1 , Left
     Command_1 = Command_1 + 1
 End If

 If Byt >= 25 Then
 Shift Command_0 , Left
     Command_0 = Command_0 + 1
 End If
 End If

 If Tik >= 10 And Tik < 22 And Start_flag = 1 Then          'if has happenned from 10 before 21 teaks - have taken "0"
 Incr Byt

 If Byt < 9 Then
 Shift Address_1 , Left
 End If

 If Byt >= 9 And Byt < 17 Then
 Shift Address_0 , Left
 End If

 If Byt >= 17 And Byt < 25 Then
 Shift Command_1 , Left
 End If

 If Byt >= 25 Then
 Shift Command_0 , Left
 End If
 End If

 Tik = 0

 If Byt = 32 Then                                           'if have taken 4 bytes, check correctness a receiving a command
 'if address or command 16-bit, check does not pass
 'Summa = Address_0 + Address_1
 'If Summa = 255 Then
    Address = Address_1
 'Else
 'Address = 0
 'End If

 'Summa = Command_0 + Command_1
 'If Summa = 255 Then
    Command = Command_1
 'Else
 'Command = 0
 'End If
  Byt = 0
  Repeat_flag = 0
  Start_flag = 0
 Stop Timer0
 End If

 Return




f. VIDEO HASILNYA













No comments:

Post a Comment