+ Reply to Thread
Results 1 to 10 of 10

Thread: Good ol' 877

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,691

    Default Good ol' 877

    Good ol' 16F877 but getting on my nerves...

    Why this does work:
    Code:
    ADCON0 = %11000001 ' Set RC clock and enable ADC
    ADCON1 = %00001110 ' Set PORTA.0 to analog,left justify, rest digital
    TRISA = %00000101  ' RA0:Analog input 0
    adcin 0,level
    and this does NOT?
    Code:
    ADCON0 = %11000001  ' Set RC clock and enable ADC
    ADCON1 = %00001110  ' Set PORTA.0 to analog,left justify, rest digital
    TRISA = %00000101   ' RA0:Analog input 0
    high adcon0.2       ' start conversion
    while adcon0.2:wend ' wait to finish
    level=adresh        ' get 8-bit value to level variable
    Ioannis

  2. #2
    Join Date
    Sep 2009
    Posts
    637

    Default Re: Good ol' 877

    I'm not 100% sure but HIGH set 2 registers, tris and port. Who know what is happening when you try to set tris of ADCON0...
    HIGH and LOW should be used only with PIN on uC.
    You should look at disassembly to know what is going on.
    I would try this:

    ADCON0 = %11000001 ' Set RC clock and enable ADC
    ADCON1 = %00001110 ' Set PORTA.0 to analog,left justify, rest digital
    TRISA = %00000101 ' RA0:Analog input 0
    adcon0.2=1 ' start conversion
    while adcon0.2:wend ' wait to finish
    level=adresh

  3. #3

    Default Re: Good ol' 877

    Not sure, but I seem to recall having an issue with putting if/then/else/endif on the same line. Might be a syntax thing where you need to put wend on its own?

    Worth a shot?

    Picster

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,691

    Default Re: Good ol' 877

    Well, the adcon0.2=1 was the solution!

    I guess last night I was not very wake to see it.

    While/Wend can be just fine on the same line, there is no problem.

    Thank you for the help,
    Ioannis

  5. #5
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    203

    Default Re: Good ol' 877

    Quote Originally Posted by picster View Post
    Not sure, but I seem to recall having an issue with putting if/then/else/endif on the same line.

    Picster
    Adding a colon, the compiler treats the next line as a new line. For example:
    Code:
    IF Box = 4 THEN : GOSUB Square : ELSEIF Triangle = 3 THEN : LOW LED : ENDIF
    Would be the same as:
    Code:
    IF Box = 4 THEN
    GOSUB Square
    ELSEIF Triangle = 3 THEN
    LOW LED
    ENDIF

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,185

    Default Re: Good ol' 877

    HIGH/LOW are really only meant to be used on PORT registers.
    Those commands also clear the corresponding TRIS bit which is at certain offset from the register (PORT) in question. That offset is 80h (at least for the '877, don't know if other parts/familes might be different).

    So when you do HIGH ADCON0.2 the compiler generates code to also clear bit 2 at the memory addess 80h "away" from ADCON0 which in this case happens to be ADCON1 and unexpected things may occur.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,691

    Default Re: Good ol' 877

    Very good explanation Henrik. Thank you.

    Ioannis

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    1,337

    Default Re: Good ol' 877

    from the user manual
    The HIGH command may only be used on output pins. If used on bits within
    variables or bits within registers (other than PORT or GPIO), unexpected behavior
    may result.
    This is more entertaining than Free to Air TV

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,691

    Default Re: Good ol' 877

    Who reads the manual...?

    Ioannis

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    1,337

    Default Re: Good ol' 877

    its best to wait till all else fails
    This is more entertaining than Free to Air TV

Similar Threads

  1. If you have good working example ..
    By hardcore in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th December 2008, 19:04
  2. pic '877 ADC...PLease HELP !!
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st January 2008, 16:41
  3. Homicidal 877 user needs help
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 20th December 2007, 14:09
  4. from 877 to 452
    By Automan in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 1st November 2004, 20:11
  5. '877 and Visual Basic 6
    By Tomas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th March 2004, 02:31

Members who have read this thread : 21

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts