Hi,

I've a problem: I'm trying to connect my pic16f887 to my pc over rs232
(with max232, which worked when using JAL).

This is the code:


#define __16f887
#include "pic14/pic16f887.h"


//#include "usart.h"

#ifndef KHZ
#define KHZ     8000
#endif

// These are fixed.  The 16f628a can only use these as transmit and
recieve.
#define TX_PORT 2
#define RX_PORT 1
#define TX_BIT  (1<<TX_PORT)
#define RX_BIT  (1<<RX_PORT)


// Twiddle these as you like BUT remember that not all values work
right!
// See the datasheet for what values can work with what clock
frequencies.
#define BAUD    19200
#define BAUD_HI 1

// This section calculates the proper value for SPBRG from the given
// values of BAUD and BAUD_HI.  Derived from Microchip's datasheet.
#if     (BAUD_HI == 1)
#define BAUD_FACTOR     (16L*BAUD)
#else
#define BAUD_FACTOR     (64L*BAUD)
#endif
#define SPBRG_VALUE     (unsigned
char)(((KHZ*1000L)-BAUD_FACTOR)/BAUD_FACTOR)

//Use these configuration words:
//0x2ff4 0x3fff

//Set the configuration words:
unsigned int __at _CONFIG1 configWord1 = 0x2FF4;
unsigned int __at _CONFIG2 configWord2 = 0x3fff;

//Setup variables
unsigned int ucharCount = 0;
unsigned int uintDelayCount = 0;
unsigned int i;
char recvd = 0;



void delay(void)
{
        
        //Delay Loop
        while ( uintDelayCount < 15000 )
        {
                //Increment the loop counter
                uintDelayCount++;
        }

        //Reset delay loop counter
        uintDelayCount = 0;
}


void stdio_init()
{
    //init_serie();
}

void main(void)
{
        //stdio_init();
        //Set PORTC to all outputs
        TRISD = 0x00;
        //OSCTUNE = 0x1f;

        uintDelayCount = 0;
        PORTD = 0;



        TRISB=TX_BIT|RX_BIT;    // These need to be 1 for USART to work

        SPBRG=SPBRG_VALUE;      // Baud Rate register, calculated by macro
        BRGH=BAUD_HI;

        SYNC=0;                 // Disable Synchronous/Enable Asynchronous
        SPEN=1;                 // Enable serial port
        TXEN=1;                 // Enable transmission mode
        CREN=1;                 // Enable reception mode
        while(1)
        {
                while(!RCIF);   // Wait until data recieved
                i=RCREG;        // Store for later
                PORTD=2;
                delay();
                while(!TRMT);   // Wait until we're free to transmit
                TXREG=i+1;      // Transmit
                PORTD=0;
                
        }
}

Simple enough, I can connect through putty to ttyUSB0 (is USB the
problem? using profilic adapter) and send commands for about 10 seconds
(like 'a', 1, '3'). It doesn't return anything though and the LED (RD1)
Stops flashing after that time, which turned up every time I pressed a
butten before those 10 sec.

What am I doing wrong?

Ruben De Smet
PS. sorry for my bad English :)
PPS. I hope this is the right place to drop my question...


------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop 
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops?   How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to