;THIS PROGRAMME DEVELOPED BY ANOOP MATHEW.M ;FOR MATTIOM TECHNOLOGIES (P) LTD,SNEHAPURAM ;PHONE-RES:+91-4802753769,MOBILE:+91-9048615367 ;email:anoopmathewmanjaly@yahoo.co.in, www.mattiom.com ;**************************************************** $ nomod51 $ include (89c52.mcu) $ include (macros.inc) ;*************************************************** ; LCD & KEYBOARD EQUALISATION ;*************************************************** key_port equ p1 lcd_port equ p0 ;*************************************************** rs_lcd bit p3.1 en_lcd bit p3.3 ;*************************************************** ; I2C,IR & ENCODER EQUALISATION ;*************************************************** scl bit p2.0 sda bit p2.1 ;*************************************************** ir_input bit p3.2 ;*************************************************** in_bit_1 bit p2.2 in_bit_2 bit p2.3 ;*************************************************** back_lite bit p2.7 ;*************************************************** ; EEPROM & AUDIO IC EQUALISATION ;*************************************************** eeprom_add equ 40 eeprom_data equ 41 ;*************************************************** pt2322_data equ 42 pt2323_data equ 43 ;*************************************************** ; AUXILURY BYTE EQUALISATION ;*************************************************** slow_vol equ 44 input_selection equ 45 volume_control equ 46 front_control equ 47 sur_control equ 48 centre_control equ 49 sub_control equ 50 bass_control equ 51 mid_control equ 52 treble_control equ 53 volume_low equ 54 volume_high equ 55 ;*************************************************** selection equ 56 sel_memory equ 57 reset_tim equ 58 liteoff_tim equ 59 ;*************************************************** ; AUXILAURY BIT EQUALISATION ;*************************************************** input_address equ 0 volume_address equ 1 front_address equ 2 sur_address equ 3 ctr_address equ 4 sub_address equ 5 bas_address equ 6 mid_address equ 7 tre_address equ 8 ;*************************************************** p_front_address equ 9 p_sur_address equ 10 p_ctr_address equ 11 p_sub_address equ 12 p_bas_address equ 13 p_mid_address equ 14 p_tre_address equ 15 ;*************************************************** first_line equ 80h first_last equ 8fh second_line equ 0c0h last_pos equ 0cfh lcd_clear equ 01h cursor_on equ 00001111b cursor_off equ 00001100b wait_delay equ 80 liteoff_delay equ 3 ;*************************************************** ; LOCK BIT EQUALISATION ;*************************************************** forward_bit bit 0 reverse_bit bit 1 mute bit 2 flag bit 3 tim_flag bit 4 sub_mute bit 5 str_2_sur bit 6 sel_flag bit 7 timer_flag bit 8 power_bit bit 9 key_flag bit 10 ir_flag bit 11 ;*************************************************** ; INTREUPT ROUTINES ;*************************************************** org reset jmp programme ;*************************************************** org exti0 jmp ir_recieve ;*************************************************** org exti1 jmp power_down ;*************************************************** org timer0 jmp auto_reset ;*************************************************** org timer1 jmp auto_start ;*************************************************** ; PROGRAMME STARTS FROM HERE ;*************************************************** PROGRAMME: ;*************************************************** mov sp,#80h call short_delay ;*************************************************** call initialize call pt_2322_initialize call pt_2323_initialize call lcd_initialize ;*************************************************** clr ex0 clr ea setb back_lite ;*************************************************** mov a,#first_line call cmd_write mov dptr,#msg_1 call dis_message mov a,#second_line call cmd_write mov dptr,#msg_2 call dis_message ;*************************************************** mov a,#'.' call data_write call long_delay ;*************************************************** ; RETRIVING SAVED DATAS ;*************************************************** mov eeprom_add,#input_address call eeprom_read mov input_selection,eeprom_data mov eeprom_add,#volume_address call eeprom_read mov volume_control,eeprom_data mov eeprom_add,#front_address call eeprom_read mov front_control,eeprom_data mov eeprom_add,#sur_address call eeprom_read mov sur_control,eeprom_data mov eeprom_add,#ctr_address call eeprom_read mov centre_control,eeprom_data mov eeprom_add,#sub_address call eeprom_read mov sub_control,eeprom_data mov eeprom_add,#bas_address call eeprom_read mov bass_control,eeprom_data mov eeprom_add,#mid_address call eeprom_read mov mid_control,eeprom_data mov eeprom_add,#tre_address call eeprom_read mov treble_control,eeprom_data ;*************************************************** call input_volume call front_volume call surround_volume call centre_volume call subwoofer_volume call bass_volume call midrange_volume call treble_volume call all_mute_on call str_sur_change_over call all_mute_off ;*************************************************** mov a,#'.' call data_write ;*************************************************** ; increace volume slowly from 0 to memory value ;*************************************************** clr ex0 mov slow_vol,volume_control mov volume_control,#0 next_slow3: mov a,volume_control cjne a,slow_vol,next_slow1 call master_volume call short_delay jmp next_slow2 next_slow1: inc volume_control call master_volume call short_delay jmp next_slow3 next_slow2: ;*************************************************** mov a,#'.' call data_write call long_delay mov a,#'.' call data_write call long_delay mov a,#'.' call data_write call long_delay ;*************************************************** mov a,#lcd_clear call cmd_write mov dptr,#msg_3 call dis_message mov a,#second_line call cmd_write mov dptr,#msg_4 call dis_message ;*************************************************** setb ex0 setb et0 setb ea ;enable all intrupts setb tr0 clr sub_mute START_PRG: call encoder call keyscan jz start_prg setb et0 setb tr0 cjne a,#3,start_prg_1 setb back_lite mov liteoff_tim,#liteoff_delay jnb f0,start_1 clr f0 clr ir_flag mov a,#lcd_clear call cmd_write call sub_on_off call input_volume call str_sur_change_over setb forward_bit setb reverse_bit call function start_1: cpl sel_flag jnb sel_flag,start_2 cjle a,#3,start_2 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write jmp start_3 start_prg_1: cjne a,#2,start_prg_2 jnb key_flag,start_prg_2 ;*************************************************** clr key_flag setb back_lite jb f0,start_3 setb forward_bit clr reverse_bit jnb sel_flag,start_123 call select_fun setb forward_bit setb reverse_bit start_123: call function jmp start_3 ;*************************************************** jmp start_3 start_prg_2: cjne a,#1,start_prg jnb key_flag,start_prg ;*************************************************** clr key_flag setb back_lite jb f0,start_3 clr forward_bit setb reverse_bit jnb sel_flag,start_456 call select_fun setb forward_bit setb reverse_bit start_456: call function jmp start_3 ;*************************************************** start_2: mov a,#cursor_off call cmd_write start_3: call keyscan jnz start_3 setb forward_bit setb reverse_bit call function jmp start_prg ;*************************************************** ; PROGRAMME INITIALISATION ;*************************************************** INITIALIZE: mov p0,#0ffh mov p1,#0ffh mov p2,#0ffh mov p3,#0ffh clr c clr flag setb f0 setb ir_flag clr mute clr rs_lcd clr en_lcd clr sel_flag clr in_bit_1 clr in_bit_2 clr key_flag clr power_bit clr back_lite setb sub_mute setb str_2_sur setb timer_flag clr reverse_bit clr forward_bit mov ie,#00000011b mov tmod,#00000001b mov sel_memory,#11 mov tl0,#0 mov th0,#0 mov reset_tim,#wait_delay mov liteoff_tim,#liteoff_delay clr ea ret ;*************************************************** ; AUTO RESET FUNCTION ;*************************************************** AUTO_RESET: djnz reset_tim,auto_r1 mov reset_tim,#wait_delay jb f0,auto_r2 mov sel_memory,#11 setb forward_bit setb reverse_bit call function auto_r2: djnz liteoff_tim,auto_r1 mov liteoff_tim,#liteoff_delay clr back_lite clr et0 clr tr0 auto_r1: reti ;*************************************************** ; POWER DOWN FUNCTION ;*************************************************** power_down: mov sel_memory,#11 setb forward_bit setb reverse_bit reti ;*************************************************** ; AUTO START FUNCTION ;*************************************************** auto_start: mov sel_memory,#11 setb forward_bit setb reverse_bit reti ;*************************************************** ; FUNCTION SELECTION ;*************************************************** FUNCTION: clr c mov a,#second_line call cmd_write mov a,sel_memory cjne a,#11,function_1 call master_function ;volume setb timer_flag mov dptr,#msg_5 call dis_message mov a,#last_pos-1 call cmd_write mov a,volume_control call hex_2_bcd call display_data jb sel_flag,function_100 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_100: mov a,#cursor_off call cmd_write ret function_1: cjne a,#10,function_2 call front_function ;front volume setb timer_flag mov dptr,#msg_6 call dis_message mov a,#last_pos-1 call cmd_write mov a,front_control call hex_2_bcd call display_data jb sel_flag,function_101 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_101: mov a,#cursor_off call cmd_write ret function_2: cjne a,#9,function_3 call surr_function ;surround volume setb timer_flag mov dptr,#msg_7 call dis_message mov a,#last_pos-1 call cmd_write mov a,sur_control call hex_2_bcd call display_data jb sel_flag,function_102 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_102: mov a,#cursor_off call cmd_write ret function_3: cjne a,#8,function_4 call sub_function ;subwoofer volume setb timer_flag mov dptr,#msg_8 call dis_message mov a,#last_pos-1 call cmd_write mov a,sub_control call hex_2_bcd call display_data jb sel_flag,function_103 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_103: mov a,#cursor_off call cmd_write ret function_4: cjne a,#7,function_5 call centre_function ;centre volume setb timer_flag mov dptr,#msg_9 call dis_message mov a,#last_pos-1 call cmd_write mov a,centre_control call hex_2_bcd call display_data jb sel_flag,function_104 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_104: mov a,#cursor_off call cmd_write ret function_5: cjne a,#6,function_6 call bass_function ;bass setb timer_flag mov dptr,#msg_10 call dis_message mov a,#last_pos-1 call cmd_write mov a,bass_control call db_values jb sel_flag,function_105 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_105: mov a,#cursor_off call cmd_write ret function_6: cjne a,#5,function_7 call mid_function ;midrange setb timer_flag mov dptr,#msg_11 call dis_message mov a,#last_pos-1 call cmd_write mov a,mid_control call db_values jb sel_flag,function_106 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_106: mov a,#cursor_off call cmd_write ret function_7: cjne a,#4,function_8 call treble_function ;treble setb timer_flag mov dptr,#msg_12 call dis_message mov a,#last_pos-1 call cmd_write mov a,treble_control call db_values jb sel_flag,function_107 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_107: mov a,#cursor_off call cmd_write ret function_8: cjne a,#3,function_9 call input_function ;input selection setb timer_flag mov dptr,#msg_13 call dis_message jb sel_flag,function_108 mov a,#first_last call cmd_write mov a,#cursor_on call cmd_write ret function_108: mov a,#cursor_off call cmd_write ret function_9: cjne a,#2,function_10 ;surround/stereo setb timer_flag mov dptr,#msg_25 call dis_message call str_sur_change_over jb sel_flag,function_109 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_109: mov a,#cursor_off call cmd_write ret function_10: cjne a,#1,function_11 setb timer_flag mov dptr,#msg_26 call dis_message call sub_on_off jb sub_mute,function_12 mov a,#last_pos-2 call cmd_write mov dptr,#msg_28 call dis_message jmp function_11 function_12: mov a,#last_pos-1 call cmd_write mov dptr,#msg_27 call dis_message function_11: jb sel_flag,function_110 mov a,#last_pos call cmd_write mov a,#cursor_on call cmd_write ret function_110: mov a,#cursor_off call cmd_write ret ;*************************************************** SELECT_FUN: jbc forward_bit,select_fun_1 push acc mov a,sel_memory cjge a,#12,select_fun_3 inc sel_memory jmp select_fun_31 select_fun_3: mov sel_memory,#0 select_fun_31: pop acc jmp vol_fun_2 select_fun_1: jbc reverse_bit,select_fun_2 push acc mov a,sel_memory cpl a jz select_fun_4 dec sel_memory jmp select_fun_41 select_fun_4: mov sel_memory,#11 select_fun_41: pop acc select_fun_2: ret ;*************************************************** ; KEYBOARD ROUTINES ;*************************************************** KEYSCAN: push b call keydown jz keyscanlast call keyconvert jbc flag,keyscanlast mov b,a call delay_msec call keydown jz keyscanlast call keyconvert jbc flag,keyscanlast cjne a,b,key_scan keyscanlast: pop b ret key_scan: clr a pop b ret ;*************************************************** KEYDOWN: mov a,key_port orl a,#11111000b cpl a ret ;*************************************************** KEYCONVERT: mov a,key_port anl a,#00111111b cjne a,#00111110b,next_one mov a,#1 jmp last_con next_one: cjne a,#00111101b,next_two mov a,#2 jmp last_con next_two: cjne a,#00111011b,next_three mov a,#3 jmp last_con next_three: cjne a,#00110111b,next_four mov a,#4 jmp last_con next_four: cjne a,#00101111b,next_five mov a,#5 jmp last_con next_five: cjne a,#00011111b,next_six mov a,#6 jmp last_con next_six: setb flag last_con: setb key_flag ret ;*************************************************** ENCODER: mov a,p1 anl a,#11000000b jnz scan call delay_usec mov a,p1 anl a,#11000000b jz scan call delay_usec cjne a,#10000000b,forward cjne a,#01000000b,reverse jmp scan forward: mov a,p1 orl a,#00111111b cpl a jz forward call delay_usec mov a,p1 anl a,#11000000b cjne a,#01000000b,scan setb back_lite jb f0,scan clr forward_bit setb reverse_bit jnb sel_flag,scan_123 call select_fun setb forward_bit setb reverse_bit scan_123: call function jmp scan reverse: mov a,p1 orl a,#00111111b cpl a jz reverse mov a,p1 anl a,#11000000b cjne a,#10000000b,scan setb back_lite jb f0,scan setb forward_bit clr reverse_bit jnb sel_flag,scan_456 call select_fun setb forward_bit setb reverse_bit scan_456: call function scan: setb tr0 ret ;*************************************************** ; AUDIO FUNCTIONS ;*************************************************** MASTER_FUNCTION: jbc forward_bit,vol_fun_1 push acc mov a,volume_control cjge a,#80,vol_fun_3 inc volume_control setb flag vol_fun_3: pop acc jmp vol_fun_2 vol_fun_1: jbc reverse_bit,vol_fun_2 push acc mov a,volume_control jz vol_fun_4 dec volume_control setb flag vol_fun_4: pop acc vol_fun_2: jnb flag,vol_fun_5 call master_volume mov eeprom_add,#volume_address mov eeprom_data,volume_control call eeprom_write clr flag vol_fun_5: ret ;*************************************************** FRONT_FUNCTION: jbc forward_bit,front_fun_1 push acc mov a,front_control cjge a,#15,front_fun_3 inc front_control setb flag front_fun_3: pop acc jmp front_fun_2 front_fun_1: jbc reverse_bit,front_fun_2 push acc mov a,front_control jz front_fun_4 dec front_control setb flag front_fun_4: pop acc front_fun_2: jnb flag,front_fun_5 call front_volume mov eeprom_add,#front_address mov eeprom_data,front_control call eeprom_write clr flag front_fun_5: ret ;*************************************************** SURR_FUNCTION: jbc forward_bit,surr_fun_1 push acc mov a,sur_control cjge a,#15,surr_fun_3 inc sur_control setb flag surr_fun_3: pop acc jmp surr_fun_2 surr_fun_1: jbc reverse_bit,surr_fun_2 push acc mov a,sur_control jz surr_fun_4 dec sur_control setb flag surr_fun_4: pop acc surr_fun_2: jnb flag,surr_fun_5 call surround_volume mov eeprom_add,#sur_address mov eeprom_data,sur_control call eeprom_write clr flag surr_fun_5: ret ;*************************************************** CENTRE_FUNCTION: jbc forward_bit,centre_fun_1 push acc mov a,centre_control cjge a,#15,centre_fun_3 inc centre_control setb flag centre_fun_3: pop acc jmp centre_fun_2 centre_fun_1: jbc reverse_bit,centre_fun_2 push acc mov a,centre_control jz centre_fun_4 dec centre_control setb flag centre_fun_4: pop acc centre_fun_2: jnb flag,centre_fun_5 call centre_volume mov eeprom_add,#ctr_address mov eeprom_data,centre_control call eeprom_write clr flag centre_fun_5: ret ;*************************************************** SUB_FUNCTION: jbc forward_bit,sub_fun_1 push acc mov a,sub_control cjge a,#15,sub_fun_3 inc sub_control setb flag sub_fun_3: pop acc jmp sub_fun_2 sub_fun_1: jbc reverse_bit,sub_fun_2 push acc mov a,sub_control jz sub_fun_4 dec sub_control setb flag sub_fun_4: pop acc sub_fun_2: jnb flag,sub_fun_5 call subwoofer_volume mov eeprom_add,#sub_address mov eeprom_data,sub_control call eeprom_write clr flag sub_fun_5: ret ;*************************************************** BASS_FUNCTION: jbc forward_bit,bass_fun_1 push acc mov a,bass_control cjge a,#15,bass_fun_3 inc bass_control setb flag bass_fun_3: pop acc jmp bass_fun_2 bass_fun_1: jbc reverse_bit,bass_fun_2 push acc mov a,bass_control jz bass_fun_4 dec bass_control setb flag bass_fun_4: pop acc bass_fun_2: jnb flag,bass_fun_5 call bass_volume mov eeprom_add,#bas_address mov eeprom_data,bass_control call eeprom_write clr flag bass_fun_5: ret ;*************************************************** MID_FUNCTION: jbc forward_bit,mid_fun_1 push acc mov a,mid_control cjge a,#15,mid_fun_3 inc mid_control setb flag mid_fun_3: pop acc jmp mid_fun_2 mid_fun_1: jbc reverse_bit,mid_fun_2 push acc mov a,mid_control jz mid_fun_4 dec mid_control setb flag mid_fun_4: pop acc mid_fun_2: jnb flag,mid_fun_5 call midrange_volume mov eeprom_add,#mid_address mov eeprom_data,mid_control call eeprom_write clr flag mid_fun_5: ret ;*************************************************** TREBLE_FUNCTION: jbc forward_bit,treble_fun_1 push acc mov a,treble_control cjge a,#15,treble_fun_3 inc treble_control setb flag treble_fun_3: pop acc jmp treble_fun_2 treble_fun_1: jbc reverse_bit,treble_fun_2 push acc mov a,treble_control jz treble_fun_4 dec treble_control setb flag treble_fun_4: pop acc treble_fun_2: jnb flag,treble_fun_5 call treble_volume mov eeprom_add,#tre_address mov eeprom_data,treble_control call eeprom_write clr flag treble_fun_5: ret ;*************************************************** INPUT_FUNCTION: jbc forward_bit,input_fun_1 push acc mov a,input_selection cjge a,#4,input_fun_3 inc input_selection setb flag input_fun_3: pop acc jmp input_fun_2 input_fun_1: jbc reverse_bit,input_fun_2 push acc mov a,input_selection jz input_fun_4 dec input_selection setb flag input_fun_4: pop acc input_fun_2: jnb flag,input_fun_5 call input_volume clr flag input_fun_5: ret ;*************************************************** STR_SUR_CHANGE_OVER: jb sel_flag,str_sur_2 cpl str_2_sur jnb f0,str_sur_2 ret str_sur_2: jb str_2_sur,str_sur_1 call surr_2_stereo mov a,#first_line+4 call cmd_write mov dptr,#msg_22 call dis_message mov a,#last_pos-7 call cmd_write mov dptr,#msg_30 call dis_message ret str_sur_1: call stereo_2_surr mov a,#first_line+4 call cmd_write mov dptr,#msg_23 call dis_message mov a,#last_pos-7 call cmd_write mov dptr,#msg_29 call dis_message ret ;*************************************************** SUB_ON_OFF: jb sel_flag,sub_on_off_2 cpl sub_mute sub_on_off_2: jb sub_mute,sub_on_off_1 call sub_mute_on mov a,#first_line call cmd_write mov dptr,#msg_24 call dis_message ret sub_on_off_1: call sub_mute_off mov a,#first_line call cmd_write mov dptr,#msg_19 call dis_message ret ;*************************************************** MASTER_VOLUME: push acc mov a,volume_control call vol_table push acc anl a,#0fh orl a,#11010000b mov volume_low,a pop acc swap a anl a,#07h orl a,#11100000b mov volume_high,a call send_pt2322_vol pop acc ret ;*************************************************** FRONT_VOLUME: push acc anl front_control,#0fh mov a,front_control call trim_table push acc anl a,#0fh orl a,#00010000b mov pt2322_data,a call send_pt_2322 pop acc anl a,#0fh orl a,#00100000b mov pt2322_data,a call send_pt_2322 pop acc ret ;*************************************************** SURROUND_VOLUME: push acc anl sur_control,#0fh mov a,sur_control call trim_table push acc anl a,#0fh orl a,#01000000b mov pt2322_data,a call send_pt_2322 pop acc anl a,#0fh orl a,#01010000b mov pt2322_data,a call send_pt_2322 pop acc ret ;*************************************************** CENTRE_VOLUME: push acc anl centre_control,#0fh mov a,centre_control call trim_table anl a,#0fh orl a,#00110000b mov pt2322_data,a call send_pt_2322 pop acc ret ;*************************************************** SUBWOOFER_VOLUME: push acc anl sub_control,#0fh mov a,sub_control call trim_table anl a,#0fh orl a,#01100000b mov pt2322_data,a call send_pt_2322 pop acc ret ;*************************************************** BASS_VOLUME: push acc anl bass_control,#0fh mov a,bass_control call tone_table anl a,#0fh orl a,#10010000b mov pt2322_data,a call send_pt_2322 pop acc ret ;*************************************************** MIDRANGE_VOLUME: push acc anl mid_control,#0fh mov a,mid_control call tone_table anl a,#0fh orl a,#10100000b mov pt2322_data,a call send_pt_2322 pop acc ret ;*************************************************** TREBLE_VOLUME: push acc anl treble_control,#0fh mov a,treble_control call tone_table anl a,#0fh orl a,#10110000b mov pt2322_data,a call send_pt_2322 pop acc ret ;*************************************************** TONE_TABLE: inc a movc a,@a+pc ret DB 00h,01h,02h,03h,04h,05h,06h,07h DB 0fh,0eh,0dh,0ch,0bh,0ah,09h,08h ;*************************************************** TRIM_TABLE: inc a movc a,@a+pc ret DB 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 ;*************************************************** VOL_TABLE: inc a movc a,@a+pc ret DB 79h,78h,77h,76h,75h,74h,73h,72h DB 71h,70h,69h,68h,67h,66h,65h,64h DB 63h,62h,61h,60h,59h,58h,57h,56h DB 55h,54h,53h,52h,51h,50h,49h,48h DB 47h,46h,45h,44h,43h,42h,41h,40h DB 39h,38h,37h,36h,35h,34h,33h,32h DB 31h,30h,29h,28h,27h,26h,25h,24h DB 23h,22h,21h,20h,19h,18h,17h,16h DB 15h,14h,13h,12h,11h,10h,9h,8h,7h DB 6h,5h,4h,3h,2h,1h,0h,0h,0h,0h,0h ;*************************************************** INPUT_VOLUME: mov a,input_selection anl a,#00000111b cjne a,#4,pt_fun_2 setb in_bit_1 clr in_bit_2 mov pt2323_data,#11001000b ;input 4 call send_pt2323 jb f0,pt_fun_66 mov a,#first_last-4 call cmd_write mov dptr,#msg_14 call dis_message pt_fun_66: jmp pt_fun_6 pt_fun_2: cjne a,#3,pt_fun_3 setb in_bit_1 clr in_bit_2 mov pt2323_data,#11001001b ;input 3 call send_pt2323 jb f0,pt_fun_67 mov a,#first_last-4 call cmd_write mov dptr,#msg_15 call dis_message pt_fun_67: jmp pt_fun_6 pt_fun_3: cjne a,#2,pt_fun_4 setb in_bit_1 clr in_bit_2 mov pt2323_data,#11001010b ;input 2 call send_pt2323 jb f0,pt_fun_68 mov a,#first_last-4 call cmd_write mov dptr,#msg_16 call dis_message pt_fun_68: jmp pt_fun_6 pt_fun_4: cjne a,#1,pt_fun_5 setb in_bit_1 clr in_bit_2 mov pt2323_data,#11001011b ;input 1 call send_pt2323 jb f0,pt_fun_69 mov a,#first_last-4 call cmd_write mov dptr,#msg_17 call dis_message pt_fun_69: jmp pt_fun_6 pt_fun_5: cjne a,#0,pt_fun_6 clr in_bit_1 setb in_bit_2 mov pt2323_data,#11000111b ;6 channel call send_pt2323 jb f0,pt_fun_6 mov a,#first_last-4 call cmd_write mov dptr,#msg_18 call dis_message pt_fun_6: mov eeprom_add,#input_address mov eeprom_data,input_selection call eeprom_write ret ;*************************************************** ALL_MUTE_ON: mov pt2323_data,#11111111b call send_pt2323 ret ;*************************************************** ALL_MUTE_OFF: mov pt2323_data,#11111110b call send_pt2323 ret ;*************************************************** SUB_MUTE_ON: mov pt2323_data,#11110111b call send_pt2323 ret ;*************************************************** SUB_MUTE_OFF: mov pt2323_data,#11110110b call send_pt2323 ret ;*************************************************** STEREO_2_SURR: mov pt2323_data,#11111000b ;sl off call send_pt2323 mov pt2323_data,#11111010b ;sr off call send_pt2323 mov pt2323_data,#11110100b ;ct off call send_pt2323 mov pt2323_data,#11010000b ;ESF off call send_pt2323 ret ;*************************************************** SURR_2_STEREO: mov pt2323_data,#11111001b ;sl on call send_pt2323 mov pt2323_data,#11111011b ;sr on call send_pt2323 mov pt2323_data,#11110101b ;ct on call send_pt2323 mov pt2323_data,#11010000b ;ESF on call send_pt2323 ret ;*************************************************** ; IR RECEIVE SUBROUTINES ;*************************************************** IR_RECIEVE: clr ea clr a setb back_lite mov liteoff_tim,#liteoff_delay setb tim_flag mov r7,#210 djnz r7,$ mov b,#7 ph0: mov c,ir_input rlc a mov r7,#140 djnz r7,$ mov r7,#140 djnz r7,$ djnz b,ph0 anl a,#11011111b cjne a,#40h,ph_time mov b,#6 ph1: mov c,ir_input rlc a mov r7,#140 djnz r7,$ mov r7,#140 djnz r7,$ djnz b,ph1 call ir_convert ; call ir_trasilate mov a,#cursor_off call cmd_write jmp ph3 ph_time: mov r7,#16 mov r6,#110 djnz r6,$ djnz r7,$-4 ph3: call delay_sec mov tl0,#0 mov th0,#0 mov reset_tim,#wait_delay setb ea reti ;*************************************************** ir_trasilate: push acc mov a,#lcd_clear call cmd_write pop acc call hex_2_bcd call display_data ret ;*************************************************** ir_convert: setb tr0 setb et0 jnb ir_flag,ir_start_1 push acc clr f0 clr ir_flag mov a,#lcd_clear call cmd_write call sub_on_off call input_volume call str_sur_change_over setb forward_bit setb reverse_bit call function pop acc ir_start_1: cjne a,#13,convert1 ;mute on/off cpl mute jnb mute,ir_convert_2 clr tr0 clr et0 call all_mute_on mov a,#second_line call cmd_write mov dptr,#msg_20 call dis_message call medi_delay ret ir_convert_2: setb tr0 setb et0 call all_mute_off mov a,#second_line call cmd_write mov dptr,#msg_5 call dis_message mov a,#last_pos-1 call cmd_write mov a,volume_control call hex_2_bcd call display_data setb sel_flag setb sub_mute call sub_on_off call medi_delay ret convert1: cjne a,#16,convert2 ;volume up mov sel_memory,#11 clr forward_bit setb reverse_bit call function call short_delay ret convert2: cjne a,#17,convert3 ;volume down mov sel_memory,#11 setb forward_bit clr reverse_bit call function call short_delay ret convert3: cjne a,#34,convert4 ;front volume down mov sel_memory,#10 clr forward_bit setb reverse_bit call function call short_delay ret convert4: cjne a,#3,convert5 ;front volume up mov sel_memory,#10 setb forward_bit clr reverse_bit call function call short_delay ret convert5: cjne a,#10,convert6 ;surround down mov sel_memory,#9 clr forward_bit setb reverse_bit call function call short_delay ret convert6: cjne a,#6,convert7 ;surround up mov sel_memory,#9 setb forward_bit clr reverse_bit call function call short_delay ret convert7: cjne a,#32,convert8 ;sub volume down mov sel_memory,#8 clr forward_bit setb reverse_bit call function call short_delay ret convert8: cjne a,#33,convert9 ;sub volume up mov sel_memory,#8 setb forward_bit clr reverse_bit call function call short_delay ret convert9: cjne a,#0,convert10 ;centre down mov sel_memory,#7 clr forward_bit setb reverse_bit call function call short_delay ret convert10: cjne a,#9,convert11 ;centre up mov sel_memory,#7 setb forward_bit clr reverse_bit call function call short_delay ret convert11: cjne a,#2,convert12 ;bass down mov sel_memory,#6 clr forward_bit setb reverse_bit call function call short_delay ret convert12: cjne a,#1,convert13 ;bass up mov sel_memory,#6 setb forward_bit clr reverse_bit call function call short_delay ret convert13: cjne a,#5,convert14 ;midrange down mov sel_memory,#5 clr forward_bit setb reverse_bit call function call short_delay ret convert14: cjne a,#4,convert15 ;midrange up mov sel_memory,#5 setb forward_bit clr reverse_bit call function call short_delay ret convert15: cjne a,#8,convert16 ;treble down mov sel_memory,#4 clr forward_bit setb reverse_bit call function call short_delay ret convert16: cjne a,#7,convert17 ;treble up mov sel_memory,#4 setb forward_bit clr reverse_bit call function call short_delay ret convert17: cjne a,#15,convert18 ;sub mute cpl sub_mute setb sel_flag call sub_on_off call cmd_write call medi_delay clr sel_flag ret convert18: cjne a,#59,convert19 ;surr to stereo cpl str_2_sur mov a,#second_line call cmd_write mov dptr,#msg_25 call dis_message setb sel_flag call str_sur_change_over call medi_delay clr sel_flag ret convert19: cjne a,#15,convert20 ;3d on &off button call short_delay ret convert20: cjne a,#38,convert21 ;input up mov sel_memory,#3 clr forward_bit setb reverse_bit call function mov a,#second_line call cmd_write mov dptr,#msg_13 call dis_message call short_delay ret convert21: cjne a,#51,convert22 ;input down mov sel_memory,#3 setb forward_bit clr reverse_bit call function mov a,#second_line call cmd_write mov dptr,#msg_13 call dis_message call short_delay ret convert22: cjne a,#12,convert23 ;power on/off cpl power_bit call short_delay ret convert23: cjne a,#42,convert24 ;front volume down mov sel_memory,#10 clr forward_bit setb reverse_bit call function call short_delay ret convert24: cjne a,#24,convert25 ;input down mov sel_memory,#3 setb forward_bit clr reverse_bit call function mov a,#second_line call cmd_write mov dptr,#msg_13 call dis_message call short_delay ret convert25: cjne a,#60,convert26 ; personal setting mov eeprom_add,#p_front_address call eeprom_read mov front_control,eeprom_data call front_volume mov eeprom_add,#p_sur_address call eeprom_read mov sur_control,eeprom_data call surround_volume mov eeprom_add,#p_ctr_address call eeprom_read mov centre_control,eeprom_data call centre_volume mov eeprom_add,#p_sub_address call eeprom_read mov sub_control,eeprom_data call subwoofer_volume mov eeprom_add,#p_bas_address call eeprom_read mov bass_control,eeprom_data call bass_volume mov eeprom_add,#p_mid_address call eeprom_read mov mid_control,eeprom_data call midrange_volume mov eeprom_add,#p_tre_address call eeprom_read mov treble_control,eeprom_data call treble_volume mov a,#second_line call cmd_write mov dptr,#msg_5 call dis_message mov a,#last_pos-1 call cmd_write mov a,volume_control call hex_2_bcd call display_data setb sel_flag setb sub_mute call sub_on_off call medi_delay ret convert26: cjne a,#41,convert27 ; personal saving mov eeprom_add,#p_front_address mov eeprom_data,front_control call eeprom_write mov eeprom_add,#p_sur_address mov eeprom_data,sur_control call eeprom_write mov eeprom_add,#p_ctr_address mov eeprom_data,centre_control call eeprom_write mov eeprom_add,#p_sub_address mov eeprom_data,sub_control call eeprom_write mov eeprom_add,#p_bas_address mov eeprom_data,bass_control call eeprom_write mov eeprom_add,#p_mid_address mov eeprom_data,mid_control call eeprom_write mov eeprom_add,#p_tre_address mov eeprom_data,treble_control call eeprom_write mov a,#second_line call cmd_write mov dptr,#msg_5 call dis_message mov a,#last_pos-1 call cmd_write mov a,volume_control call hex_2_bcd call display_data setb sel_flag setb sub_mute call sub_on_off call medi_delay convert27: ret ;*************************************************** ; LCD FUNCTIONS ;*************************************************** DATA_WRITE: mov lcd_port,a ; post acc at lcd data input setb rs_lcd ; set rs high (data) call bit_delay setb en_lcd ; receive data byte call bit_delay clr en_lcd ; drop the selection line call delay_msec ret ; return to caller ;*************************************************** CMD_WRITE: mov lcd_port,a ; post acc at lcd data input clr rs_lcd ; set rs low (instruction) call bit_delay setb en_lcd ; receive instruction byte call bit_delay clr en_lcd ; drop the selection line call delay_msec ret ; return to caller ;*************************************************** LCD_INITIALIZE: mov a,#03ch ; lenght(8 bits),2lines,char5x7 call cmd_write; needs 3 times this byte (1st) call delay_msec call cmd_write ; (second) call delay_msec call cmd_write; (third) call delay_msec mov a,#00001100b call cmd_write; call delay_msec mov a,#06h ; move direction & shift display call cmd_write; call delay_msec mov a,#lcd_clear; lcd clear call cmd_write; clear display call delay_msec ret ;*************************************************** DIS_MESSAGE: clr a movc a,@a+dptr ; get byte pointed by dptr inc dptr ; point to the next byte jz dis_msg call data_write; it was data, write it to lcd jmp dis_message dis_msg: ret ;*************************************************** ; EEPROM READ & WRITE ;*************************************************** EEPROM_READ: clr a clr c call i2c_start jc x42 mov a,#10100000B clr acc.0 call i2c_out jc x43 mov a,eeprom_add call i2c_out jc x43 ;now read data from eeprom call i2c_start jc x43 mov a,#10100000B setb acc.0 call i2c_out jc x43 call i2c_in mov eeprom_data,a call i2c_nack clr c x43: call i2c_stop x42: call delay_usec ret ;*************************************************** EEPROM_WRITE: clr ea clr c call i2c_start jc x44 mov a,#10100000B clr acc.0 call i2c_out jc x45 mov a,eeprom_add call i2c_out jc x45 mov a,eeprom_data call i2c_out jc x45 x44: call i2c_stop call delay_msec call delay_msec x45: setb ea ret ;*************************************************** ; PT2323 & PT2322 DATA SENDING ROUTINES ;*************************************************** SEND_PT2323: clr c call i2c_start jc send_pt2323_1 mov a,#10010100b call i2c_out jc send_pt2323_2 mov a,pt2323_data call i2c_out jc send_pt2323_1 send_pt2323_2: call i2c_stop send_pt2323_1: ret ;*************************************************** PT_2323_INITIALIZE: mov pt2323_data,#11110000b ;fl on call send_pt2323 mov pt2323_data,#11110010b ;fr on call send_pt2323 mov pt2323_data,#11110100b ;ct on call send_pt2323 mov pt2323_data,#11110110b ;sub on call send_pt2323 mov pt2323_data,#11111000b ;sl on call send_pt2323 mov pt2323_data,#11111010b ;sr on call send_pt2323 mov pt2323_data,#11010000b ;esf on call send_pt2323 mov pt2323_data,#10010001b;+6dB call send_pt2323 ret ;*************************************************** SEND_PT_2322: clr c call i2c_start jc send_pt2322_1 mov a,#10001000b call i2c_out jc send_pt2322_2 mov a,pt2322_data call i2c_out jc send_pt2322_1 send_pt2322_2: call i2c_stop send_pt2322_1: ret ;*************************************************** SEND_PT2322_VOL: clr c call i2c_start jc send_pt2322_vol1 mov a,#10001000b call i2c_out jc send_pt2322_vol2 mov a,volume_high call i2c_out jc send_pt2322_vol2 mov a,volume_low call i2c_out jc send_pt2322_vol1 send_pt2322_vol2: call i2c_stop send_pt2322_vol1: ret ;*************************************************** PT_2322_INITIALIZE: mov pt2322_data,#0ffh call send_pt_2322 mov pt2322_data,#11000111b call send_pt_2322 mov pt2322_data,#01110100b call send_pt_2322 ret ;*************************************************** ; I2C BUS FUNCTIONS ;*************************************************** I2C_START: setb sda setb scl jnb sda,x46 ; jump if not high jnb scl,x46 ; jump if not high call bit_delay clr sda call bit_delay clr scl clr c jmp x47 x46: setb c x47: ret ;*************************************************** I2C_STOP: clr sda call bit_delay setb scl call bit_delay setb sda ret ;*************************************************** I2C_OUT: mov b,#8 x48: rlc a mov sda,c call bit_delay setb scl call bit_delay clr scl djnz b,x48 setb sda call bit_delay setb scl call bit_delay mov c,sda call bit_delay clr scl ret ;*************************************************** I2C_IN: clr a setb sda mov b,#8 x49: call bit_delay setb scl call bit_delay mov c,sda rlc a clr scl djnz b,x49 ret ;*************************************************** I2C_ACK: clr sda nop setb scl call bit_delay clr scl ret ;*************************************************** I2C_NACK: setb sda nop setb scl call bit_delay clr scl ret ;*************************************************** ; DELAY FUNCTIONS ;*************************************************** BIT_DELAY: nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop ret ;*************************************************** DELAY_uSEC: mov r1,#0 djnz r1,$ ret ;*************************************************** DELAY_MSEC: mov r1,#25 d_mswait: mov r2,#25 djnz r2,$ djnz r1,d_mswait ret ;*************************************************** DELAY_SEC: mov r1,#10 d_swait2: mov r2,#20 d_swait1: mov r3,#50 djnz r3,$ djnz r2,d_swait1 djnz r1,d_swait2 ret ;*************************************************** SHORT_DELAY: call delay_sec call delay_sec ret ;*************************************************** MEDI_DELAY: call delay_sec call delay_sec call delay_sec call delay_sec ret ;*************************************************** LONG_DELAY: call delay_sec call delay_sec call delay_sec call delay_sec call delay_sec call delay_sec call delay_sec call delay_sec ret ;*************************************************** ; DATA CONVERTIONS ;*************************************************** HEX_2_BCD: mov b,#10 ; divide by 10 div ab ; do divide swap a ; move result to high of a orl a,b ; or in remainder ret ; return to caller ;*************************************************** BCD_2_HEX: push acc ; save value anl a,#0f0h ; keep high bits swap a ; get to low mov b,#10 ; 10 decimal mul ab ; multiply mov b,a ; store in b pop acc ; recover bcd value anl a,#0fh ; keep low nybble add a,b ; add in high ret ; return to caller ;*************************************************** BCD_2_ASCII: inc a movc a,@a+pc ret db "0123456789" ;*************************************************** DISPLAY_DATA: push acc swap a anl a,#0fh call bcd_2_ascii call data_write pop acc anl a,#0fh call bcd_2_ascii call data_write ret ;*************************************************** DB_VALUES: clr c push acc push acc mov a,#last_pos-1 call cmd_write mov dptr,#msg_21 call dis_message pop acc cjne a,#7,db_value1 mov a,#last_pos-2 call cmd_write mov a,#"0" call data_write pop acc ret db_value1: jc lessthan mov a,#last_pos-3 call cmd_write mov a,#"+" call data_write jmp db_value2 lessthan: mov a,#last_pos-3 call cmd_write mov a,#"-" call data_write db_value2: pop acc mov dptr,#db_ascii movc a,@a+dptr call data_write ret ;*************************************************** ; LCD MESSAGE DATAS ;*************************************************** MSG_1: DB " INITIALIZING ",0 MSG_2: DB "Please wait",0 MSG_3: DB " <<<<>>>>",0 MSG_4: DB " POWER AMPLIFIER",0 MSG_5: DB "MASTER VOL ",0 MSG_6: DB "FRONT VOL ",0 MSG_7: DB "SURROUND VOL ",0 MSG_8: DB "SUB VOL ",0 MSG_9: DB "CENTRE VOL ",0 MSG_10: DB "BASS ",0 MSG_11: DB "MIDRANGE ",0 MSG_12: DB "TREBLE ",0 MSG_13: DB "INPUT SELECTION",0 MSG_14: DB "AUX-1",0 MSG_15: DB "AUX-2",0 MSG_16: DB "AUX-3",0 MSG_17: DB "AUX-4",0 MSG_18: DB "5.1CH",0 MSG_19: DB "SUB ",0 MSG_20: DB " ALL MUTE ",0 MSG_21: DB "dB",0 MSG_22: DB "STEREO ",0 MSG_23: DB "SURRND ",0 MSG_24: DB " ",0 MSG_25: DB "MODE ",0 MSG_26: DB "SUBWOOFER ",0 MSG_27: DB "ON",0 MSG_28: DB "OFF",0 MSG_29: DB "SURROUND",0 MSG_30: DB " STEREO",0 MSG_31: DB "STANDBY",0 MSG_32: DB " MATTIOM TECH ",0 MSG_33: DB " SNEHAPURAM ",0 DB_ASCII: DB "7654321 12345678" ;*************************************************** END