Postea todo el codigo y el esquematico con el que vas a trabajar asi te prodre ayudar mejor
Follow along with the video below to see how to install our site as a web app on your home screen.
Nota: This feature currently requires accessing the site using the built-in Safari browser.
'DEFINICION OSCILADOR EXTERNO
@ device xt_osc ; oscilador externo XT
define osc 4 ; especifica que se va a utilizar uno de 4 Mhz
INCLUDE "modedefs.bas"
;DEFINICIONES
;Define parametro de conversion A/D
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
; VARIABLES
Tsample VAR Word
Mode VAR Byte
Dummy VAR Byte
D VAR Byte
Res Var Word
Temp1 Var Word
TRISA = 1
TRISB = 2
PAUSE 10
Symbol RS232_out = 0 ; RB0 is RS232 output
Symbol RS232_in = 1 ; RB1 is RS232 input
; CONSTANTES
CR CON 13
LF CON 10
;Enviar mensajes por RSR232
Again:
SEROUT RS232_out,N9600,[LF,CR,"TERMOMETRO DIGITAL CON PIN DE SALIDA RS232"]
SEROUT RS232_out,N9600,[LF,CR," =============================="]
Esample:
SEROUT RS232_out,N9600,[LF,LF,CR,"SEELCIONE TIEMPO DE MUESTREO EN SEG:"]
SERIN RS232_in,N9600,5000,ESample,#TSample
SEROUT RS232_out,N9600,[#Tsample]
EMode:
SEROUT RS232_out, N9600,[LF,CR,"GRADOS C(C) O GRADOS F(F):"]
SERIN RS232_in,N9600,5000,EMode,Mode
SEROUT RS232_out,9600,[Mode]
Estart:
SEROUT RS232_out, N9600,[LF,CR,"PRESIONE ENTER PARA INICIAR…"]
SERIN RS232_in,N9600,5000,Estart,Dummy
SEROUT RS232_out,N9600,[LF,CR]
TSample = TSample*1000
;inicio conversion
ADCON1 = %10001110
ADCON0 = %01000001
More:
D ="C"
ADCIN 0,Res
Temp1 = 48*Res ;Convierte a grados C
Temp1 = Temp1/100
IF Mode ="F" THEN ;selecionar grados F
Temp1 = Temp1 * 18
Temp1 = Temp1+320
Temp1 = Temp1/10
D = "F"
ENDIF
SEROUT RS232_out,N9600,[LF,CR, #Temp1,D]
PAUSE Tsample
GOTO More
END
'RELOJ CALENDARIO CON PIC 16F84a ,LCD Y DS 1307
'CONFIGURACION OSCILADOR
@ device xt_osc ; oscilador externo XT
define osc 4 ; especifica que se va a utilizar uno de 4 Mhz
'CONFIFURACION LCD
Define LCD_DREG PORTA
Define LCD_DBIT 0
Define LCD_RSREG PORTA
Define LCD_RSBIT 6
Define LCD_EREG PORTA
Define LCD_EBIT 7
Define LCB_BITS 4
Define LCD_LINES 2
Define LCD_COMMANDUS 2000
Define LCD_DATAUS 50
'CONFIGURACION DS1307
SQWpin var PORTB.0
SCLpin var PORTB.1
SDApin var PORTB.2
'CONFIGURACION DE PINES
DecButton var PORTB.4 ' Presionar para decrementar
SetButton var PORTB.5 ' Presionar para memorizar
IncButton var PORTB.6 ' Presionar para incrementar
'CPNFIGURACION MESES,DIAS
Data @0,74,97,110,70,101,98,77,97,114,65,112,114
' Jan Feb Mar Apr
Data 77,97,121,74,117,110,74,117,108,65,117,103
' May Jun Jul Aug
Data 83,101,112,79,99,116,78,111,118,68,101,99
' Sep Oct Nov Dec
Data 84,117,101,87,101,100,84,104,117,70,114,105
' Tue Wed Thu Fri
Data 83,97,116,83,117,110,77,111,110
' Sat Sun Mon
'CREACION DE VARIABLES
CounterA var byte
CounterB var byte
CounterC var byte
CounterD var byte
RTCSec var byte
RTCMin var byte
RTCHour var byte
RTCWDay var byte
RTCDay var byte
RTCMonth var byte
RTCYear var byte
RTCCtrl var byte
SetTime var byte
SetSec var byte
SetMin var byte
SetHour var byte
SetDay var byte
SetMonth var byte
SetYear var byte
TimeOut var word
'CONTANTES DEL PROGRAMA
ButtonRepeat con 200
'inicio del programa
goto JumpStart
ConvertBCD:
CounterB=CounterA DIG 1
CounterB=CounterB<<4
CounterB=CounterB+CounterA DIG 0
Return
DisplayMonth:
CounterB=CounterB*3-3
DisplaySequence:
For CounterA=CounterB to CounterB+2
Read CounterA,CounterD
LCDOut CounterD
Next CounterA
Return
'SUBRUTINA PARA NUMERO DE DIAS Y MESES
FindDays:
LookUp SetMonth-1,[31,28,31,30,31,30,31,31,30,31,30,31],CounterA
If SetMonth=2 then
If (SetYear&$03)=0 then CounterA=29
endif
Return
'SUBRUTINA RETARDO DE BOTONES
SetButtonRelease:
LCDOut $FE,1
While SetButton=0:Wend
Pause 250
Return
JumpStart:
CMCON=%00000111
TRISA=%00000000
TRISB=%11111111
OPTION_REG.7=0
Pause 200
ReDisplay:
LCDOut $FE,1
ReDisplayLoop:
'RUTINA PARA LEER INTEGRADO DS1307
I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]
If RTCSec.7=1 then goto SetUpPreset
If SetButton=0 then
Gosub SetButtonRelease
goto Setup
endif
'RUTINA PARA MOSTRAR VALOR EN LCD
LCDOut $FE,$80
If RTCHour.6=1 then
CounterA=(RTCHour>>4)&$01
else
CounterA=(RTCHour>>4)&$03
endif
CounterA=CounterA*10+(RTCHour&$0F)
If RTCHour.6=1 then
LCDOut #CounterA
else
LCDOut #CounterA Dig 1,#CounterA Dig 0
endif
LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":"
LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," "
IF RTCHour.6=1 then
If RTCHour.5=1 then
LCDOut "PM"
else
LCDOut "AM"
endif
endif
LCDOut " ",$FE,$C0
CounterB=RTCWDay*3+33
Gosub DisplaySequence
LCDOut " ",#(RTCDay>>4)&$0F,#RTCDay&$0F," "
CounterB=((RTCMonth>>4)&$0F)*10+(RTCMonth&$0F)
Gosub DisplayMonth
LCDOut " 20",#(RTCYear>>4)&$0F,#RTCYear&$0F,$FE,$80
Pause 250 ' Repeat about 4 times/sec
Goto ReDisplayLoop
SetupPreset:
RTCSec=$00 '
RTCMin=$15
RTCHour=$13
RTCWDay=$01
RTCDay=$12
RTCMonth=$06
RTCYear=$02
RTCCtrl=$10
Setup:
SetTime=RTCHour.6
If SetTime=1 then
SetHour=(RTCHour>>4)&$01
else
SetHour=(RTCHour>>4)&$03
endif
SetHour=SetHour*10+(RTCHour&$0F)
If SetTime=1 then
If RTCHour.5=1 then
If SetHour<12 then SetHour=SetHour+12
else
If SetHour=12 then SetHour=0
endif
endif
SetMin=((RTCMin>>4)&$0F)*10+(RTCMin&$0F)
SetSec=((RTCSec>>4)&$0F)*10+(RTCSec&$0F)
SetYear=((RTCYear>>4)&$0F)*10+(RTCYear&$0F)
SetMonth=((RTCMonth>>4)&$0F)*10+(RTCMonth&$0F)
SetDay=((RTCDay>>4)&$0F)*10+(RTCDay&$0F)
CounterC=0
TimeOut=0
SetupLoop:
LCDOut $FE,1,"Set "
If CounterC=0 then
LCDOut "Mode"
endif
If CounterC=1 then
LCDOut "Hours"
endif
If CounterC=2 then
LCDOut "Minutes"
endif
If CounterC=3 then
LCDOut "Seconds"
endif
If CounterC=4 then
LCDOut "Year : 20"
endif
If CounterC=5 then
LCDOut "Month"
endif
If CounterC=6 then
LCDOut "Day"
endif
If CounterC<>4 then LCDOut " :"
SetupDisplayLoop:
If CounterC=0 then
LCDOut $FE,$8B
If SetTime=0 then
LCDOut "24HR"
else
LCDOut "12HR"
endif
LCDOut $FE,$8B
endif
If CounterC=1 then
CounterA=SetHour
If SetTime=1 then
LCDOut $FE,$8E
If CounterA<12 then
LCDOut "AM"
else
LCDOut "PM"
endif
If CounterA=0 then CounterA=12
If CounterA>12 then CounterA=CounterA-12
endif
LCDOut $FE,$8C,#CounterA
If CounterA<10 then LCDOut " "
LCDOut $FE,$8C
endif
If CounterC=2 then
LCDOut $FE,$8E,#SetMin
If SetMin<10 then LCDOut " "
LCDOut $FE,$8E
endif
If CounterC=3 then
LCDOut $FE,$8E,#SetSec
If SetSec<10 then LCDOut " "
LCDOut $FE,$8E
endif
If CounterC=4 then
LCDOut $FE,$8D,#SetYear DIG 1,#SetYear Dig 0
LCDOut $FE,$8D
endif
If CounterC=5 then
LCDOut $FE,$8C
CounterB=SetMonth
Gosub DisplayMonth
LCDOut $FE,$8C
endif
If CounterC=6 then
LCDOut $FE,$8A,#SetDay
If SetDay<10 then LCDOut " "
LCDOut $FE,$8A
endif
SetupEntryLoop:
If DecButton=0 then
If CounterC=0 then
If SetTime=0 then
SetTime=1
else
SetTime=0
endif
endif
If CounterC=1 then
If SetHour=0 then
SetHour=23
else
SetHour=SetHour-1
endif
endif
If CounterC=2 then
If SetMin=0 then
SetMin=59
else
SetMin=SetMin-1
endif
endif
If CounterC=3 then
If SetSec=0 then
SetSec=59
else
SetSec=SetSec-1
endif
endif
If CounterC=4 then
If SetYear=0 then
SetYear=99
else
SetYear=SetYear-1
endif
endif
If CounterC=5 then
If SetMonth=1 then
SetMonth=12
else
SetMonth=SetMonth-1
endif
Gosub FindDays
If SetDay>CounterA then SetDay=CounterA
endif
If CounterC=6 then
Gosub FindDays
If SetDay=1 then
SetDay=CounterA
else
SetDay=SetDay-1
endif
endif
Pause ButtonRepeat
TimeOut=0
Goto SetUpDisplayLoop
endif
If IncButton=0 then
If CounterC=0 then
If SetTime=1 then
SetTime=0
else
SetTime=1
endif
endif
If CounterC=1 then
If SetHour=23 then
SetHour=0
else
SetHour=SetHour+1
endif
endif
If CounterC=2 then
If SetMin=59 then
SetMin=0
else
SetMin=SetMin+1
endif
endif
If CounterC=3 then
If SetSec=59 then
SetSec=0
else
SetSec=SetSec+1
endif
endif
If CounterC=4 then
If SetYear=99 then
SetYear=0
else
SetYear=SetYear+1
endif
endif
If CounterC=5 then
If SetMonth=12 then
SetMonth=1
else
SetMonth=SetMonth+1
endif
Gosub FindDays
If SetDay>CounterA then SetDay=CounterA
endif
If CounterC=6 then
Gosub FindDays
If SetDay=>CounterA then
SetDay=1
else
SetDay=SetDay+1
endif
endif
Pause ButtonRepeat
TimeOut=0
Goto SetupDisplayLoop
endif
If SetButton=0 then
CounterC=CounterC+1
TimeOut=0
If CounterC>6 then
LCDOut $FE,1,"Memorizar"
CounterA=SetHour
If SetTime=1 then
If CounterA>12 then CounterA=CounterA-12
If CounterA=0 then CounterA=12
endif
Gosub ConvertBCD
RTCHour=CounterB
If SetTime=1 then
RTCHour.6=1
If SetHour=>12 then RTCHour.5=1
endif
CounterA=SetMin
Gosub ConvertBCD
RTCMin=CounterB
'
CounterA=SetSec
Gosub ConvertBCD
RTCSec=CounterB
CounterA=SetYear
Gosub ConvertBCD
RTCYear=CounterB
CounterA=SetMonth
Gosub ConvertBCD
RTCMonth=CounterB
CounterA=SetDay
Gosub ConvertBCD
RTCDay=CounterB
CounterA=SetYear+4
CounterB=SetMonth
If SetMonth<3 then
CounterA=CounterA-1
CounterB=CounterB+12
endif
CounterD=(SetDay+(153*CounterB-457)/5+365*CounterA+CounterA/4-CounterA/100+CounterA/400+2) MOD 7
RTCWDay=CounterD+1
I2CWrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]
Pause 1000
Gosub SetButtonRelease
Goto ReDisplay
endif
Gosub SetButtonRelease
Goto SetupLoop
endif
Pause 1
TimeOut=TimeOut+1
If TimeOut>20000 then goto ReDisplay
Goto SetupEntryLoop
End
; Programa PWM con Hardware con el pic 16f628A con un ciclo util del 50%
;y frecuencia de 38 KHZ aproximadamente
@ device xt_osc ; oscilador externo XT
define osc 4 ; especifica que se va a utilizar uno de 4 Mhz
CMCON = 7 ' PUERTO A DIGIAL
VRCON = 0 ' A/D Voltage referencia deshabilitado
TRISB = %11110000 ' B.3=PWM,B.0,B.1,B.2 LEDs
PR2 = 25 ' Seleecion PWM para aproximadamente 38KHz
CCPR1L = 13 ' PWM Duty-Cycle a 50%
CCP1CON = %00001100 ' modo de seleccion = PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescaler
LOOP:
high PortB.0
pause 50
low PortB.0
pause 50
high PortB.1
pause 50
low PortB.1
pause 50
high PortB.2
pause 50
low PortB.2
pause 50
goto LOOP
; Programa PWM con el pic 16f84A con un ciclo util del 50%
@ device xt_osc ; oscilador externo XT
define osc 4 ; especifica que se va a utilizar uno de 4 Mhz
PWM portB.3,127,30 ; Sacar 30 pulsos PWM por el puerto b3 con un ciclo util del 50%
IF (hour=3) and(minu=13)= then GOSUB alarma ; si son las 3:00 ir a alarma
.
.
.
alarma:
SOUND porta.0[100,20,50,20] 'generar tonos por el puerto A0 Donde puede estar ubicado un parlante , un led
RETURN ; regresar al comando que lo lllamo
DEFINE LCD_DREG PORTD 'UTILIZO PORTB COMO DATOS
DEFINE LCD_DBIT 4 'LE INDICO QUE UTILIZO MODO DE 4 BITS
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 1 ' RS EN PORTB.1
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 0 'ENABLE BIT EN PORTB.0
DEFINE LCD_LINES 2 'LCD DE DOS LINEAS
DEFINE LCD_COMMAMDUS 2000
DEFINE LCD_DATAUS 50
DEFINE OSC 20
DEFINE ADC_SAMPLEUS 50
TRISA = %00000000
TRISB = %11110000
TRISC = %00000000
TRISD = %00001111
TRISE = 0
CONTADOR VAR BYTE
TECLA VAR WORD
CLAVE VAR WORD
DIG1 VAR BYTE
DIG2 VAR BYTE
DIG3 VAR BYTE
DIG4 VAR BYTE
CODIGO VAR BYTE
PRUEBA VAR BYTE
VAR1 VAR BYTE
PORTC.0=0
PORTC.1=0
PORTC.2=0
PORTC.3=0
Pause 500
'ADCON1=%00000110
CONTADOR = 1
'PORTA=%00000011
INTCON.0=0 'BORRO FLAG
INTCON.7=0
PORTA = 0
Low PORTB.2
Pause 500
ON INTERRUPT GoTo APRETO
INTCON = %10001000
Pause 300
VAR1=0
LOOP: INTCON = %10001000
PORTC = 0
LCDOut $Fe,$C0,DEC(VAR1)
Pause 300
Disable
PORTA=VAR1
GoTo LOOP
APRETO: INTCON.7=0 'DESAHBILITO TODAS LAS INT.
INTCON.3=0 'DESHABILITO RB4-RB7 INT.
INTCON.0=0
Disable
PORTC = 0
PORTC.0 = 0 ' Columna 1 = 0
PORTC.1 = 1 ' Columna 2 = 1
PORTC.2 = 1 ' Columna 3 = 1
PORTC.3 = 1 ' Columna 4 = 1
IF PORTB.4 = 0 Then VAR1 = 7 ' tecla "7"
IF PORTB.5 = 0 Then VAR1 = 4 ' tecla "4"
IF PORTB.6 = 0 Then VAR1 = 1 ' tecla "1"
IF PORTB.7 = 0 Then VAR1 = 20 ' tecla "*"
PORTC.0 = 1 ' Columna 1 = 1
PORTC.1 = 0 ' Columna 2 = 0
PORTC.2 = 1 ' Columna 3 = 1
PORTC.3 = 1 ' Columna 4 = 1
IF PORTB.4 = 0 Then VAR1 = 8 ' tecla "8"
IF PORTB.5 = 0 Then VAR1 = 5 ' tecla "5"
IF PORTB.6 = 0 Then VAR1 = 2 ' tecla "2"
IF PORTB.7 = 0 Then VAR1 = 0 ' tecla "0"
PORTC.0 = 1 ' Columna 1 = 1
PORTC.1 = 1 ' Columna 2 = 1
PORTC.2 = 0 ' Columna 3 = 0
PORTC.3 = 1 ' Columna 4 = 1
IF PORTB.4 = 0 Then VAR1 = 9 ' tecla "9"
IF PORTB.5 = 0 Then VAR1 = 6 ' tecla "6"
IF PORTB.6 = 0 Then VAR1 = 3 ' tecla "3"
IF PORTB.7 = 0 Then VAR1 = 40 ' tecla "#"
Resume
Enable
@devicext_osc ; oscilador externo XT
define osc 4
define LCD_DREG PORTD
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTD
DEFINE LCD_RSBIT 5
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 4
P1 VAR BYTE
P2 VAR BYTE
P3 VAR BYTE
ADCON1=%100
INICIO:
PAUSE 300
POTEN1:
ADCON0=%1000001
GOSUB MEDIR
P1= ADRESH
POTEN2:
ADCON0=%1001001
GOSUB MEDIR
P2=ADRESH
POTEN3:
ADCON0=%1011001
GOSUB MEDIR
P3=ADRESH
PAUSE 200
X=(P1*500)/254 'ESTA ES LA OPERACION QUE QUISE IMPLEMENTAR
Y=(P2*30)/254 'ESTA ES LA OPERACION QUE QUISE IMPLEMENTAR TAMBIEN PARA MI OTRO EJE
LCDOUT $FE,1
LCDOUT $FE,$1,"E.LONGITUDINAL:"
LCDOUT $FE,$8C,DEC X
LCDOUT $FE,$C0,"E.TRANSFERSAL:"
LCDOUT $FE,$CC,DEC Y
GOTO inicio
MEDIR:
PAUSE 50
ADCON0.2=1
PAUSEUS 50
RETURN
END