Jump to content

HOEK

EstablishedMember
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

0 Neutral

About HOEK

  • Rank
    Newbrie
  1. /*------------------------------------------------------------* Filename: strncmp.c *------------------------------------------------------------*/ int strcmp(char *first, char *second, int count) { if( !count ) return(0); while(--count&& *first&& *first== *last) { first++; last++; } return(first-last); } "Size" should be "Count" Function should also be declared in .h file or at top of source. And const char should be normal chars as you explained above. Hope that works.
  2. Thanks for the help - I'm a South African student, so the C2C++ compiler will have to wait till a decent pay check arrives. The only difference between C and C++ is that the one is object-orientated and the one is procedural? The normal compiler should be able to cope with this problem in my opinion. In any case, here is the function for you ++ guys, have a look and let me know if it ticks... /*------------------------------------------------------------* Filename: strncmp.c Purpose: Compares first n characters of two strings for lexical order. Inputs: char first: First string to compare char second: Second string to compare int size: Max. number of chars to compare Outputs: returns <0 if first<last returns 0 if first=last returns >0 if first>last *------------------------------------------------------------*/ int strcmp( char *first, char *second, int size) { if( !count ) return(0); while(--count&& *first&& *first== *last) { first++; last++; } return(first-last); }
  3. Thanks guys. I've tried to port the GNU strncmp function to SourceBoost, in essence it just compares strings character by character and returns 0 for a match. The problem is that the C2C compiler can only handle one const char pointer in a function call, which means I can't send both strings or arrays to a single function. I've seen the guys in HTPIC using the strncmp function, so there must be a workaround??
  4. Is there a way to use a character array in a if statement, something like: if ( array[] == {'C','O','M','M','A','N','D'} ) { do stuff... }
  5. The scenario: I need 2 RS232 ports on the PIC16F877A. So I use the hardware USART as one and the software generated USART as another. Hardware USART works fine. Software USART can transmit but not receive. Here is a code snippet that echos the Software USART receive bit to the Hardware USART. /*--------------------------------------------------------------------* Configuration *--------------------------------------------------------------------*/ //Clock Frequency #pragma CLOCK_FREQ 4000000 //Include files #include <system.h> #define test_bit(x,y) (x&(1<<y)) // Macro from system.h //RS232 settings #pragma RS232_TXPORT PORTA #pragma RS232_RXPORT PORTA #pragma RS232_TXPIN 2 #pragma RS232_RXPIN 1 #pragma RS232_BAUD 9600 //Burn configuration word asm __config _XT_OSC & _CP_OFF & _DEBUG_OFF & _CPD_OFF & _LVP_OFF & _BODEN_ON & _PWRTE_ON & _WDT_OFF & _WRT_256 /*--------------------------------------------------------------------* Variables *--------------------------------------------------------------------*/ char t; /*--------------------------------------------------------------------* Writes a single character to the USART *--------------------------------------------------------------------*/ void sendChar(char c) { if( ! test_bit(txsta, TXEN) ) { set_bit(txsta, TXEN ); } while( ! test_bit(pir1, TXIF) ) { nop(); } txreg=c; } /*--------------------------------------------------------------------* Main Routine *--------------------------------------------------------------------*/ void main() { //Global Interrupt disable disable_interrupt( GIE ); //Set Up SW USART Comms trisa = 2; // Set Up Serial Comms trisc = 11000000b; // Set Tx, Rx Registers to 0 txsta=0; rcsta=0; // High Baud Rate Select. Baud = 9600 @ 4MHz set_bit(txsta,BRGH); spbrg=25; // Set SYNC to 0 for Async Mode clear_bit(txsta,SYNC); // Enable Serial Port set_bit(rcsta,SPEN); //Echo from one port to another //Read in char t = getchar(); // Infinite Loop while( 1==1 ) { if( t != 0 ) { sendChar('$'); sendChar(t); sendChar('#'); nop(); } } } This code does'nt work off course. Any guru out there that can tell me what's wrong? Thanks
  6. Here is a code snippet showing the configuration and the Interrupt Service Routine: /*--------------------------------------------------------------------* Configuration *--------------------------------------------------------------------*/ #pragma CLOCK_FREQ 4000000 #include #define test_bit(x,y) (x&(1< //Additional RS232 #pragma RS232_TXPORT PORTA #pragma RS232_TXPIN 3 //4 on 877 #pragma RS232_RXPORT PORTA #pragma RS232_RXPIN 2 //3 on 877 #pragma RS232_BAUD 9600 #pragma TRUE_RS232 1 /*--------------------------------------------------------------------* Interrupt Service Routine *--------------------------------------------------------------------*/ void interrupt(void) { RxFlag = SWPORTA; // Test PORTA status if ( test_bit(pir1, RCIF) ) { if( test_bit(rcsta, FERR) || test_bit(rcsta, OERR) ) { clear_bit(rcsta,CREN); nop(); set_bit(rcsta,CREN); } else if ( RxFlag != 0 ) //Just messing without success... { RxByte = rcreg; handleSwUsartChar(RxByte); } handleReceivedChar(rcreg); } }
  7. Hi all. I'm trying to use both the 877's hardware USART as well as a software USART generated by the C2C compiler in order to communicate with two serial devices. I'm able to transmit from both USARTs. How can I distinguish between a hardware USART Rx interrupt and the software USART Rx interrupt? I can catch the hardware interrupt, but not the Software one. Thanks in advance
×
×
  • Create New...