Pic 18f452


Closed Thread
Results 1 to 3 of 3

Thread: Pic 18f452

  1. #1
    Join Date
    Apr 2009
    Posts
    2

    Default Pic 18f452

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    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

    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.
    Code:
    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Apr 2009
    Posts
    2

    Default

    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

Similar Threads

  1. Problem accessing keypad on PortB (LabX1, PIC 18F452)
    By scorpion4377 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th January 2009, 04:52
  2. Pic 16 F877 to 18F452...?
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st October 2007, 16:54
  3. IC2 pic 18f452 program problems
    By MrSafe in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 20th September 2007, 19:55
  4. Help, problems first time with 18F452 PIC
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2005, 21:49
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th March 2005, 00:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts