Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

strange problem ! pic18f4550 & pic16f84a serial communication .

Status
Not open for further replies.

amenoera

New Member
hi everybody .

here its is what i want to do exactly and wat i got .

i want to connect 4 pic16f84a to 1 pic18f4550 serially . and every pic16 send
its portb value to pic18 serially . then pic18 send the value to my pc usb . so i write the code for pic16 and test it on my pc serial port and its working fine and send the right value . what when connect to pic18 , pic18 send wrong values . here is my code and hope to find anything wrong ?
*****************************************************

' pic16f84a code
include "modedefs.bas"
define osc 4
TRISB = %11111111 ' portb all input
PORTB = %00000000 ' portb 0
TX VAR PORTA.2 ' transmmit
B0 VAR BYTE ' var for store portb value
B1 VAR BYTE ' var for store portb value

start :
B0 = PORTB
PAUSE 100
B1 = PORTB
IF B1 = B0 THEN start
IF B1<> B0 THEN SEROUT TX,N9600,[B1]
B1 = B0
GOTO start
*********************************************************
'pic18f4550 code
Include "modedefs.bas"
INCLUDE "DT_INTS-18.bas"
DEFINE OSC 20
PORTD = 0
TRISD = %11111111
ASM
INT_LIST macro
INT_Handler USB_INT, _DoUSBService, ASM, yes
endm
INT_CREATE
endasm

USBBufferSizeTX con 8
USBBufferSizeRX con 8
USBBufferCount Var Byte
USBBufferIn var byte[8]
USBBufferOut Var Byte[8]
DataToSend var byte[8]
RX VAR PORTD.1
VAR0 VAR BYTE
asm
SendUSB macro array
variable i=0
while i<8
MOVE?BB (array+i),(_USBBufferOut+i)
i+=1
endw
L?CALL _DoUSBOut
endm
endasm
SwHwInit:
GOSUB DoUSBinit:
Start:


'**********************************************************************
serin rx,N9600,VAR0
datatosend[4] = VAR0
'**********************************************************************


@ SendUSB _DataToSend
gosub dousbin
goto start
DoUSBIn:
@ INT_DISABLE USB_INT
USBBufferCount = USBBufferSizeRX
USBService
USBIn 1, USBBufferin, USBBufferCount, Timeout
Timeout:
@ INT_ENABLE USB_INT
return
DoUSBOut:
@ INT_DISABLE USB_INT
WaitPC:
USBBufferCount = USBBufferSizeTX
USBService
USBOut 1, USBBufferOut, USBBufferCount, Waitpc
@ INT_ENABLE USB_INT
return
usb_device_state var byte EXT
CONFIGURED_STATE CON EXT
DoUSBinit:
pause 500
usbinit
repeat
usbservice
until usb_device_state = CONFIGURED_STATE
@ INT_ENABLE USB_INT
return
DoUSBService:
usbservice
@ INT_RETURN
**********************************************************

thanks , regards
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top