Vizitator DANIEL1919 Postat Iunie 2, 2006 Partajează Postat Iunie 2, 2006 Am un pic(16F74) shi am facut urmatorul program pt. el(ABIA AM INCEPUT SA INVAT LIMBAJUL ASTA :rolleyes: ): '************************************************************* '* Name : DIGITAL CONTROLED VOLUME.BAS * '* Author : Daniel * '* Notice : ALL RIGHTS RESERVED® 2006 * '* Date : 1/6/2006 * '* Notes : FOR PIC 16F74! * '* : * '************************************************************ @ DEVICE PIC16F74, XT_OSC @ DEVICE PIC16F74, WDT_ON @ DEVICE PIC16F74, PWRT_ON @ DEVICE PIC16F74, PROTECT_OFF I CON 254 ' Control Byte CLR CON 1 ' Clear the display LINE_1 CON 128 ' Point to beginning of line 1 LINE_2 CON 192 ' Point to beginning of line 2 CGRAM CON 64 ' Point to Cgram within LCD SHIFT_L CON 24 ' Shift display left SHIFT_R CON 28 ' Shift display right TRISA = %11111111 ' PortA as inputs OPTION_REG.7=0 TRISB.0 = 1 INTCON =$00 ' Disable interrups, and clear INT flags V_POW VAR BYTE : V_POW = 0 V_UP VAR BYTE : V_UP = 0 ' Volume up Bvar, initialized to zero V_DOWN VAR BYTE : V_DOWN = 0 ' Volume down Bvar, initialized to zero V_MUTE VAR BYTE : V_MUTE = 0 ' Mute on/off Bvar, initialized to zero VOL VAR WORD VOL_L VAR VOL.BYTE1 : VOL_L = 55 ' Right channel data byte POW_BUT VAR PORTA.3 'POWER BUTTON UP_BUT VAR PORTA.4 ' Volume up button DOWN_BUT VAR PORTA.5 ' Volume down button MUTE_BUT VAR PORTA.2 ' Mute button POWER VAR PORTD.4 : LOW POWER MUTE VAR PORTC.4 : low MUTE ' Mute pin, turned on, to prevent pop-up noise CS VAR PORTC.7 : high CS ' Chip select pin SDI VAR PORTC.6 : high SDI ' Data out pin SCLK VAR PORTC.5 : high SCLK ' Clock out pin dB_SIGN VAR BIT ' Decible sign dB VAR WORD ' dB variable dB10 VAR BYTE ' 1st dB digit dB1 VAR BYTE ' 2nd dB digit FLAG VAR BIT ' General variable DEFINE OSC 4 DEFINE LCD_DREG PORTB ' Set LCD Data port DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus DEFINE LCD_RSREG PORTB ' Set LCD Register Select port DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit DEFINE LCD_EREG PORTB ' Set LCD Enable port DEFINE LCD_EBIT 3 ' Set LCD Enable bit DEFINE LCD_RWREG PORTB DEFINE LCD_RWBIT 2 DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits) DEFINE LCD_LINES 2 ' Set number of lines on LCD DEFINE LCD_COMMANDUS 1500 ' Set command delay time in us DEFINE LCD_DATAUS 100 ' Set data delay time 100 us DEFINE SHIFT_PAUSEUS 2000 ' Slow clock by an additional 2000 us DEFINE BUTTON_PAUSE 100 ' Set button debounce delay to 100ms POWER_START: BUTTON POW_BUT, 0, 255, 0,V_POW, 1, POW_CON POW_CON: pow var byte pow = pow + 1 if pow = 2 then power_off high portd.0 LCDOUT " HELOO!! " PAUSE 2000 LCDOUT I,CLR, " DOM' DANIEL" HIGH PORTD.4 LCDOUT I,LINE_2, " Welcome !!" pause 2000 lcdout I,clr gosub shift gosub DB_VALUE pause 1500 high MUTE gosub dB_LCD gosub MUTE_LCD ' Calculate decible equivalent power_off: lcdout i,clr lcdout i,128," GOOD BYE" pause 1500 lcdout i,clr low portd.0 high MUTE pause 100 low portd.4 goto POWER_START ' Turn mute off VOLUME: Button UP_BUT, 0, 255, 127, V_UP, 1, VOL_UP ' Volum up button Button DOWN_BUT, 0, 255, 127, V_DOWN, 1, VOL_DOWN ' Volum down button Button MUTE_BUT, 0, 255, 0, V_MUTE, 1, MUTE_CON ' Mute buttong VOL_UP: IF ( VOL_L = 255 ) Then MAX_LIMIT ' Check if volume is at max level VOL_L = VOL_L + 1 ' Increment VOL_L GoSub SHIFT ' Send data to PGA2310 GoSub DB_VALUE ' Calculate decible vale GoSub dB_LCD ' Show volume Ddecible value, then mute state gosub MUTE_LCD ' Show mute status on LCD GOTO VOLUME ' Return to to check buttons if any presed VOL_DOWN: IF ( VOL_L = 1 ) Then MIN_LIMIT ' Check if volume is at min level VOL_L = VOL_L - 1 ' Decrement VOL_L GoSub SHIFT ' Send data to PGA2310 GoSub DB_VALUE ' Calculate decible vale GoSub dB_LCD ' Show volume Ddecible value, then mute state gosub MUTE_LCD ' Show mute status on LCD GoTo VOLUME ' Return to to check buttons if any presed MUTE_CON: Toggle MUTE gosub MUTE_LCD GoTo VOLUME SHIFT : low CS pauseus 100 ShiftOut SDI, SCLK, 5, [ VOL\16 ] high CS PAUSEUS 100 high SDI Return dB_VALUE : IF ( VOL_L >= 192 ) Then DB_SIGN = 1 DB = 3150 - ( 5 * ( 2550 - ( VOL_L * 10 ))) DB10 = DB / 100 dB1 = DB // 100 DB1 = DB1 / 10 Else DB_SIGN = 0 dB = ( 5 * ( 2550 - ( VOL_L * 10 ))) - 3150 DB10 = DB / 100 dB1 = DB // 100 DB1 = DB1 / 10 EndIF Return dB_LCD : FLAG = 1 if ( db10 = 0 ) AND ( DB1 = 0 ) THEN LCDOut I, clr, " Volume ", DEC DB10, " dB"', DEC VOL_L FLAG = 0 ENDIF IF ( flag = 1 ) and ( DB_SIGN = 1 ) Then LCDOut I, clr, " Volume ", DEC DB10, ".", DEC DB1, " dB"', DEC VOL_L ENDIF IF ( flag = 1 ) and ( DB_SIGN = 0 ) Then LCDOut I, clr, " Volume -", DEC DB10, ".", DEC DB1, " dB"', DEC VOL_L ENDIF Return MUTE_LCD : IF MUTE = 1 Then LCDOut i, line_2, " Mute OFF" Else ' Else LCDOut i, line_2, " Mute ON " EndIF Return MAX_LIMIT : LCDOut I, CLR, " Max volume !!!" GoSub MUTE_LCD GOTO VOLUME MIN_LIMIT : LCDOut i, clr, " Min volume !!!" GoSub MUTE_LCD GoTo VOLUME End Problema este ca nu face decat sa controleze volumul...atat! Nu am reusit sa introduc in program shi un cod(pt. Ir.) pentru a controla amplif. cu o telecomanda... :axe: Daca avetzi cumva un program care sa regleze digital volumul shi sa aiba shi o optiune pt telecomanda,shi encoder, va rog sa il postatzi aici sau sa il trimiteti prin e-mail la adresa: [email protected]! Multumesc... Link spre comentariu
Postări Recomandate
Creează un cont sau autentifică-te pentru a adăuga comentariu
Trebuie să fi un membru pentru a putea lăsa un comentariu.
Creează un cont
Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!
Înregistrează un nou contAutentificare
Ai deja un cont? Autentifică-te aici.
Autentifică-te acum