PDA

View Full Version : Pic 18f452



mamr_r
- 6th April 2009, 22:15
Good day guys
i m using pic 18f452 for a project to receive a number (for example;003) from matlab. the pic is to receive the number and put it in port d as a binary number. the problem is that it didn't work and i didn't know why;



the matlab code is

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SerPIC = serial('COM1');
set(SerPIC,'BaudRate', 9600, 'DataBits', 8, 'Parity', 'none','StopBits', 1, 'FlowControl', 'none');
fopen(SerPIC);
fprintf(SerPIC, '%s' ,'003'),
fclose(SerPIC)
delete(SerPIC)
clear SerPIC

%%%%%%%%%%%%%%%%%%%%%%%%%%%%



and the microcode code is



'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
INCLUDE "modedefs.bas"
DEFINE HSER_BAUD 9600
define HSER_CLROERR 1
char var byte
command var byte
loop:
high porta.1
Hserin 20000, loop, [char, dec3 command]
Select Case command
Case 0
portd = 0
Case 1
portd = 1
Case 2
portd = 2
Case 3
portd = 3
CASE ELSE
end Select
Goto loop
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''



could you help me with that
and i ll be very thankful of any suggestions

mister_e
- 6th April 2009, 23:24
We dončt know your Config Fuse setting, we don't know your OSC value, we don't know how your PIC is connected to your PC.... a bit hard to suggest something :o

I would suggest to use your PIC and send some Data to your PC (any terminal software). From there you should know if your PIC works properly, case not... check your Hardware, config fuses setting and so on.

HTH

PS: Forget the timeout for now, and add the DEFINEs for HSEROUT/HSERIN , see the manual about that.

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 1 ' 115200 Baud @ 14.745MHz, 0.0%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

mamr_r
- 7th April 2009, 04:31
thanks for the replay
well,

I was using another code and when i run the matlab code i provided before, portc.6 which is RS232 RX blink twice. that means the pic is receiving the data.the problem is how to read that data. the OSC value is 4 and the pic is on a flash-lab 77 that has max233 built on it. I am using 9600 baud rate for matlab, pic and my pc.


the code that shows a blinking in the RX pin is:

Include "bs2defs.bas"
DEFINE OSC 4
SerI var PORTC.0
TRISD = %00000000
PortD = %00000000
Received var byte
High PORTA.1
pause 1000
Serin seri,N9600, ["3"],Received 'to receive i
PORTD = received
low porta.1
end