Problem with project with pic


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2008
    Posts
    81

    Cool Problem with project with pic

    hello
    My project works fine in proteus
    the more real it does not work
    can someone tell me
    here is the program
    thank you
    TX:
    @ DEVICE PIC16F876A
    @ DEVICE PIC16F876A, WDT_off
    @ DEVICE PIC16F876A, PWRT_ON
    @ DEVICE PIC16F876A, PROTECT_off
    @ DEVICE PIC16F876A, XT_OSC

    DEFINE OSC 4 ' DEFINE OSCILADOR EM 4MHz
    DEFINE HSER_TXSTA 20h ' ABILITA TX , BRGH = 0
    DEFINE HSER_BAUD 2400 ' SETA BAUD RATE
    DEFINE HSER_SPBRG 25 ' 2400 BAUD @ 4MHz, 0,17%
    DEFINE HSER_CLROERR 1 ' LIMPA OVERFLOW AUTOMATICAMENTE

    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2

    CMCON=7
    DEFINE ADC_BITS 10 ' ADCIN resolution (Bits)
    DEFINE ADC_CLOCK 1 ' ADC clock source (Fosc/8)
    DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec)
    PORTA=0
    TRISA=%00000111
    PORTB=0
    TRISB=0
    ADCON1=%11000000




    RAWA VAR WORD
    RAWB VAR WORD
    TOPA VAR word
    TOPB VAR WORD
    AOHM VAR BYTE
    BOHM VAR BYTE
    I VAR BYTE
    REL VAR BYTE
    LCDOUT $fe,1, " By Cesar"
    pause 2000

    START:

    TOPA=0
    FOR I=0 to 19
    ADCIN 0, RAWA
    PAUSEUS 50
    TOPA=TOPA+RAWA+1
    NEXT
    RAWA=TOPA/20
    AOHM=RAWA*/25

    TOPB=0
    FOR I=0 to 19
    ADCIN 1, RAWB
    PAUSEUS 50
    TOPB=TOPB+RAWB+1
    NEXT
    RAWB=TOPB/20
    BOHM=RAWB*/25
    LCDOUT $fe,2,"ADC=",dec3 AOHM," TX1"
    lcdout $fe,$C0,"ADC=",dec3 BOHM," TX2"
    pause 100
    HSEROUT [AOHM,BOHM]
    GOTO START

    RX:
    @ DEVICE pic16F628A
    @ DEVICE pic16F628A, WDT_OFF
    @ DEVICE pic16F628A, PWRT_OFF
    @ DEVICE pic16F628A, BOD_OFF
    @ DEVICE pic16F628A, PROTECT_OFF
    @ DEVICE pic16F628A, MCLR_OFF
    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT

    DEFINE OSC 4
    CMCON = 7 'PortA digital
    TRISB =%00000010
    PORTB =%00000010
    TRISA = 0
    PORTA = 0
    DEFINE OSC 4 'DEFINE OSCILADOR EM 4MHz
    DEFINE HSER_RCSTA 90h 'ABILITA RX
    DEFINE HSER_BAUD 2400 'SETA BAUD RATE
    DEFINE HSER_SPBRG 25 '2400 BAUD @ 4MHz, 0,17%
    DEFINE HSER_CLROERR 1 'LIMPA OVERFLOW AUTOMATICAMENTE

    AOHM VAR BYTE
    BOHM VAR BYTE
    REL VAR BYTE

    INICIO:
    hSERIN [AOHM,BOHM]
    if (AOHM>55) THEN
    PORTB.4 = 1
    PORTB.5 = 0
    PORTB.6 = 0
    PORTB.7 = 1
    ELSE
    IF (AOHM<45) THEN
    PORTB.4 = 0
    PORTB.5 = 1
    PORTB.6 = 1
    PORTB.7 = 0
    else
    PORTB.4 = 0
    PORTB.5 = 0
    PORTB.6 = 0
    PORTB.7 = 0
    IF (BOHM>55) THEN
    PORTB.4 = 1
    PORTB.5 = 0
    PORTB.6 = 1
    PORTB.7 = 0
    ELSE
    IF (BOHM<45) THEN
    PORTB.4 = 0
    PORTB.5 = 1
    PORTB.6 = 0
    PORTB.7 = 1
    ELSE
    PORTB.4 = 0
    PORTB.5 = 0
    PORTB.6 = 0
    PORTB.7 = 0
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    GOTO INICIO

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: Problem with project with pic

    What's it supposed to do and what DOES it do?
    Does it work at all, what works, what doesn't?

    Things like that would be some pretty useful information for anyone trying to help.

    My first GUESS, since you say it works in the simulator, is a problem with the oscillators(s). If I'm not mistaken Proteus doesn't actually simulate the oscillator, you just tell it a frequency and it runs at that. In real life things are not perfect and the oscillator, especially the internal one the '628, might be off in frequency enough to cause i mismatch in the baudrate timing.

    If your outputs on the receiver doesn't act the way you expect them to then my vote goes to a read-modify-write issue. Your clock frequency is quite slow and RMW issues usually shows up at much higher frequencies but perhaps you have your outputs heavily loaded?

    /Henrik.

  3. #3
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Problem with project with pic

    hello Henrik
    I'll put an external crystal in PIC16F628A
    I will do this

    you think you have problem in codes
    a hug
    thank you
    Last edited by cesar35; - 26th September 2012 at 19:23.

  4. #4
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Problem with project with pic

    hello
    Today I did as you said with external crystal
    not worked
    I'll see what's wrong
    thank you

Similar Threads

  1. Strange problem with an 18F4580 based project
    By malc-c in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 19th December 2010, 10:45
  2. Problem with SMS Project: Using 16F877A
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 22nd October 2009, 02:33
  3. Help with PIC project
    By davekav in forum General
    Replies: 3
    Last Post: - 17th April 2008, 23:15
  4. gps project
    By chuckad in forum GPS
    Replies: 2
    Last Post: - 9th February 2007, 02:52
  5. First Project
    By Andy M in forum General
    Replies: 2
    Last Post: - 18th August 2004, 20:10

Members who have read this thread : 1

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