PDA

View Full Version : rs485 communication



dreamman
- 10th June 2007, 20:26
Hi i work on dmx receive code and some problem ,i want to receive 1 chanel dmx512 signal but what is my problem on this code ?



DEFINE OSC 20
CMCON = %00000111 TRISA = %11111110
TRISB = %00000010
OPTION_REG.7 = 1
T2CON = %00000100

' Set receive register to receiver enabled

RCSTA = %11010000

' Set transmit register to transmitter disabled

TXSTA = %00000110

' Set baud rate

SPBRG = 4


led1 var portb.4


Dummy var byte
Adres con 20
Break var bit
Adresteller var word


Ontvangbyte1 var byte

PWMLED1 var byte

pwmled1 = 0

while 1=1
if RCSTA.2 = 1 then ' framing error -> break

dummy = RCREG ' rcsta.2 reset

break = 1

portb.8 = 1 zet led 4 aan

Else

IF PIR1.5 = 1 then

if break = 1 then

break = 0

dummy = RCREG

adresteller = 0

else

dummy = RCREG

if adres = adresteller then

ontvangbyte1 = dummy
endif

adresteller = adresteller + 1

endif

endif

endif

'PWM VOOR 1 LEDje:

if pwmled1<=ontvangbyte1 then

led1 = 1

else

led1 = 0

endif

pwmled1 = pwmled1 + 1

if pwmled1 = 255 then pwmled1 = 0

wend

skimask
- 10th June 2007, 21:47
CMCON = %00000111 TRISA = %11111110
error here


while 1=1
What? :)


portb.8 = 1 zet led 4 aan
will never work, well it might, but not the way you'd expect


'PWM VOOR 1 LEDje:
If that's meant to be a label, won't work...


if pwmled1 = 255 then pwmled1 = 0
If you've got pwmled1 defined as a byte, no need to reset it, it'll just roll over to zero