PDA

View Full Version : Problem with project with pic



cesar35
- 26th September 2012, 17:36
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

HenrikOlsson
- 26th September 2012, 18:16
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.

cesar35
- 26th September 2012, 19:18
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

cesar35
- 27th September 2012, 00:27
hello
Today I did as you said with external crystal
not worked
I'll see what's wrong
thank you