Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 17th March 2008, 05:55 AM   #1
Default strange problem ! pic18f4550 & pic16f84a serial communication .

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
__________________
jax
amenoera is offline  
Reply

Tags
communication, pic, pic16f84a, problem, serial, strange

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
WIRELESS & SERIAL COMMUNICATION DTMF Micro Controllers 11 22nd July 2005 11:18 PM
Serial communication problem tbrown Micro Controllers 12 13th February 2004 11:32 AM
Serial Communication Problem. Need some help please. Beefer3 Micro Controllers 5 12th November 2003 05:14 PM
strange color camera problem schrodingerscat Electronic Projects Design/Ideas/Reviews 5 4th October 2003 08:25 PM
Serial Cable Problem ElectroGeek_87 Micro Controllers 4 13th August 2003 11:48 AM



All times are GMT. The time now is 11:32 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker