way dont work ?

Status
Not open for further replies.

procos

New Member
i have this code :
DEVICE = 16F877
XTAL = 20

LCD_DTPIN = PORTD.4
LCD_RSPIN = PORTE.0
LCD_ENPIN = PORTE.1
LCD_INTERFACE = 4 ' 4-bit Interface
LCD_LINES = 4
'LCD_TYPE = 0

' Alias pins
Symbol RST = PORTA.2
Symbol IO = PORTC.1
Symbol SCLK = PORTC.3

Dim ADVAL AS WORD ' Create ADVAL to store result
ON_INTERRUPT Goto myint
' Allocate variables
Dim rtcyear as byte
Dim rtcday as byte
Dim rtcmonth as byte
Dim rtcdate as byte
Dim rtchr as byte
Dim rtcmin as byte
Dim rtcsec as byte
Dim rtccontrol as byte

Low RST ' Reset RTC
Low SCLK
'ADCON1 = 7 ' PORTA and E digital
'Low PORTE.2 ' LCD R/W low = write
'Delayms 1000 ' Wait for LCD to startup

' Define ADC parameters
ADIN_RES = 10 ' 10-bit result required
ADIN_TAD = FRC ' RC OSC chosen
ADIN_STIME = 150 ' Allow 50us sample time


TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
Delayms 500 ' Enable TMR1 overflow interrupt
Dim TICK as Byte SYSTEM ' make sure that the variable is in bank0 if they are to be used in the interrupt handler

Dim SECONDS as Byte ' Elapsed seconds
Dim MINUTES as Word ' Elapsed minutes
Dim LOOPS as Word
DIM WRD1 as WORD
WRD1= 1000
minutes = 0 ' Clear time
seconds = 0
T1CON = $01 ' Turn on Timer1, prescaler = 1
INTCON = $C0 ' Enable global interrupts, peripheral interrupts
PIE1 = $01



' Set initial time to 8:00:00AM 07/16/99
rtcyear = $99
rtcday = $06
rtcmonth = $07
rtcdate = $16
rtchr = $08
rtcmin = 0
rtcsec = 0
'Gosub settime ' Set the time
Goto mainloop ' Skip subroutines


'DECLARE SERIAL_DATA 8 ' Set SEROUT and SERIN data bits to 8 (default)
DECLARE SDA_PIN PORTC.4
DECLARE SCL_PIN PORTC.3
DECLARE RSOUT_PIN PORTC.6
DECLARE RSIN_PIN PORTC.7
DECLARE SERIAL_BAUD 9600
' Point to the hardware interrupt handler

Delayms 100
'ALL_DIGITAL = True
Goto MAIN ' jump over the interrupt handler and sub

' Assembly language interrupt handler
MYINT:


Movlw $C0 ; Prepare to set TMR1 high register
Movwf TMR1H ; Set TMR1H to C0h
Incf TICK,F ; INCREMENT TICK COUNT
Bcf PIR1, 0 ; Clear interrupt flag
'Context Restore

' Subroutine to update the minutes and seconds variables
GET_TIME:

PIE1 = 0 ' Mask the interrupt while we're messing with TICK
seconds = seconds + (tick / 61) ' Add the accumulated seconds
tick = tick // 61 ' Retain the left-over ticks
PIE1 = $01 ' Interrupt on again
minutes = minutes + (seconds / 60) ' Add the accumulated minutes
seconds = seconds // 60 ' Retain the left-over seconds
Return 'MAIN ' Return to the main program
'repeat
'DELAYMS WRD1
'goto MAIN
'RETURN

MAIN:
'Cls

' PIE1 = 0 ' Mask the interrupt while we're messing with TICK
'seconds = seconds + (tick / 61) ' Add the accumulated seconds
'tick = tick // 61 ' Retain the left-over ticks
'PIE1 = $01 ' Interrupt on again
'minutes = minutes + (seconds / 60) ' Add the accumulated minutes
'seconds = seconds // 60
'RETURN
'repeat
'UNTIL loop


' Subroutine to write time to RTC
Settime:
RST = 1 ' Ready for transfer
Shout IO,SCLK,LSBFIRST,[$8e,0] ' Enable write
RST = 0 ' Reset RTC
RST = 1 ' Ready for transfer
' Write all 8 RTC registers in burst mode
Shout IO,SCLK,LSBFIRST,[$be,rtcsec,rtcmin,rtchr,rtcdate,rtcmonth,rtcday,rtcyear,0]
RST = 0 ' Reset RTC
Return
'-------------------------------------------------------------------------------
' Subroutine to read time from RTC
gettime:
RST = 1 ' Ready for transfer
Shout IO,SCLK,LSBFIRST,[$bf] ' Read all 8 RTC registers in burst mode
Shin IO,SCLK,LSBPRE,[rtcsec,rtcmin,rtchr,rtcdate,rtcmonth,rtcday,rtcyear,rtccontrol]
RST = 0 ' Reset RTC
Return
'-------------------------------------------------------------------------------
Goto Mainloop' Main program loop - updates the LCD with the time
Mainloop:
cls
While 1 = 1

loops = 0

'Goto loop
loop:
loops = loops + 1

'DelayMS 100 ' Wait .1 second
'DELAYMS WRD1 ' Delay for 1000ms

ADVAL = Adcin 0 ' Read channel 0 to adval (0-1023)
ADVAL = (ADVAL */ 500) >> 2 ' equates to: (adval * 500)/1024
'ADVAL = ADVAL *1000
Print at 1,1,"DC Volts= ",Dec (ADVAL/100),".", Dec2 ADVAL," V " ' Display the decimal value
Delayms 100 ' Wait .1 second
'repeat
'until mainloop
'Goto loop
'loop:
loops = loops + 1

Gosub GET_TIME ' Update minutes and seconds
'repeat 'get_time
'until GET_TIME
Print at 2,1, "Time: ",DEC5 minutes, ":", DEC2 seconds ' Display the elapsed time
Delayms 300
'goto loop
'repeat
'until GET_TIME
' loop:
loops = loops + 1 'DELAYMS WRD1 ' Delay for 1000ms
'until loops = 0
'Goto loop ' Repeat main loop
'Goto MAIN
' Display time on LCD
Print at 3,1, hex2 rtcmonth,"/",hex2 rtcdate,"/",hex2 rtcyear
Print at 4,1, hex2 rtchr,":",hex2 rtcmin,":",hex2 rtcsec
Delayms 300 ' Do it approx 3 times a second
'repeat
'until get_time '
goto loop ' Do it forever
'
Wend
'return
'GOTO MAIN

help my!!!
way dont work all :
AD conversion
elapsed time
real time clock

thx very much for any help, opinion
bye
 
Don't try and write one huge program, build it a section at a time, testing and confirming that each stage works correctly. That way you should know where the problem lies, and where to look.
 
Re: thx nigel

procos said:
every piece of this code is work, but together dont!!!

Put them together in smaller pieces, and try and find which part stops it working.
 
The language above is BASIC - Beginners Allpurpose Symbolic Instruction Code.

You can get a free trial version at **broken link removed**

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…