Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 17, 2024, 03:41:53 15:41


Login with username, password and session length


Pages: [1]
Print
Author Topic: please help me check  (Read 5871 times)
0 Members and 1 Guest are viewing this topic.
kctan
Guest
« on: February 03, 2006, 05:34:04 05:34 »

i am using the proton to write this code but i don't know y when i give the input signal until 5 the portb.3 can't be light up? can anyone help me check? thanks 1st Smiley
 
here is the coding (proton)
 
Device = [/size]16F877A
XTAL [/color][/size]= 20
TRISB = %00000000
TRISC = %11111111
ALL_DIGITAL [/color][/size]= true
Dim i As Byte
start:
i = 1
If
PORTC.0 = 1 Then
PORTB.0 = 1
Else
PORTB.0 = 0
EndIf
If
PORTB.0 =1 Then
i = i + 1
EndIf
While i = 5
DelayMS 300
PORTB.3 = 1
Wend
Logged
ero
Junior Member
**
Offline Offline

Posts: 43

Thank You
-Given: 12
-Receive: 27


« Reply #1 on: February 03, 2006, 12:00:18 12:00 »

The problem is the code. Lets look together;
Start:
        i = 1                          '_________ if program comes here second time (i) become 1 again for this reason this line must be put before (start:)
        If PORTC.0 = 1 Then
            PORTB.0 = 1
          Else
            PORTB.0 = 0
        EndIf
       
        If PORTB.0 =1 Then   _____'********the problem is here
          i = i + 1                    'i become (i=i+1=2) 2 here and
        EndIf                          '________________program pass over here
       
        While i = 5                 '____________the (i) is two here, and program pass
        pause 300                 '____________to the end
        PORTB.3 = 1
        Wend
                                           '_____________________now program is here and there is not any code
                                           '_____________________For this reason, we have to put here;
       goto start ' ____________this command.

The right code should be as follows;
i=1
start:
'-------------
        If PORTC.0 = 1 Then
             PORTB.0 = 1
        Else
            PORTB.0 = 0
        EndIf
       
        If PORTB.0 =1 Then
           i = i + 1
        EndIf
       
       While i = 5
        delayms 300
        PORTB.3 = 1
        Wend
      goto start


ERO
« Last Edit: February 03, 2006, 12:03:21 12:03 by ero » Logged
Parmin
Hero Member
*****
Offline Offline

Posts: 582

Thank You
-Given: 496
-Receive: 133


Very Wise (and grouchy) Old Man


« Reply #2 on: February 03, 2006, 10:14:39 22:14 »

I agree with ERO,

Since the program is not in a loop, there is no increment of i larger than the integer 2.

If there is a loop, it seems that the loop should go to the label "start"  thus passing the label, i get set back to the integer 1.

Since i cannot get over the value of integer 2,  the while i = 5 condition is never met, so PortB.3 will never turn on.
Logged

If I have said something that offends you, please let me know, so I can say it again later.
kctan
Guest
« Reply #3 on: February 06, 2006, 04:08:47 04:08 »

thanks for all of the help Smiley .
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC