O que estou tentando é usar o exemplo do CCS para escrever uma string (ou seja uma palavra inteira) e não consegui porque parece que o PIC 16F876 parece ficar resetando.
quando eu ligo o PIC aparece a mensagem no hyperterminal "Enter a string of text. The maximum number of characters is 50" quer dizer que posso digitar até 50 caracteres, mas quando eu escrevo 3 ou 4 caracteres ele mostra a mensagem inicial novamente "Enter a string of text. The maximum number of characters is 50" quer dizer só pode estar resetando. depois disso se vc escreve 1 caractere ele aparece a mensagem novamente, as vezes eu consigo escrever 3 ou 4 caracteres e apertar enter e ele funciona como deveria ser (aparecer a mensagem STATISTICS) mas na proxima vez já da erro.
veja a figura:

o código é esse, é um exemplo do CCS:
- Código: Selecionar todos
/*
#if defined(__PCB__)
#include <16c56.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2) // Jumpers: 11 to 17, 12 to 18
*/
//#elif defined(__PCM__)
#include <16F876.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#fuses XT//,NOBROWNOUT//,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NODEBUG,NOWRT
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
/*
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#endif
*/
#include <string.h>
#include <input.c>
#define STRING_SIZE 51 // The number of characters allowed to input
//int ttrtrtr = 250;
// This function cleans up the string. It removes all
// punctuation and all multiple spaces. It also removes
// any leading and trailing spaces.
void clean_up_str(char *str) {
char separators[8];
char *ptr, *clean_str;
strcpy(separators," ,;.\"!?"); // initialize variables
clean_str=str;
do
{
ptr = strpbrk(str,separators); // search for punctuation or space
if(ptr == str) // if first char is punct or space
{
++str; // simply go to next char
}
else if(ptr == 0) // if search returns end of str
{
while(*str != 0) // loop until end of string
*clean_str++ = *str++; // copy characters to remove punct and spaces
if(*--clean_str == ' ') // if the last char is a space
*clean_str = 0; // remove it and terminate the string
else
*++clean_str = 0; // otherwise just terminate the string
}
else // if somewhere in middle of string
{
while(ptr != str) // loop until pointers match up
*clean_str++ = *str++; // copy chars to remove punct and spaces
*clean_str++ = ' '; // then add a space
}
} while(ptr != 0); // loop until through string
}
// This function return the number of words in the string.
// The words must be separated by a single space.
int get_num_words(char *str) {
int retval;
retval=0; // initialize variable
while(*str!=0) // loop through all of string
{
str = strchr(str,' '); // find first space
retval++; // increment counter
if(*str == 0) // if at the end, quit
break;
else // otherwise increment pointer
str++;
}
return(retval);
}
// This function returns the number of words in the string
// excluding any repeated words. The words must be separated
// by a single space.
int get_num_unique_words(char *str) {
int retval, i;
char temp_str[STRING_SIZE], space[2];
char *word, *srch_string, *srch_word;
strcpy(temp_str,str); // copy the string to temp string
strcpy(space," "); // initialize local variables
retval=0;
srch_string=temp_str;
word=strtok(temp_str,space); // find next word
while(word!=0) // loop until all words looked at
{
retval++;
srch_string+= strlen(word)+1; // points to next word after 0 in temp
srch_word=temp_str;
while(srch_word!=0) // loop while not end of words
{
srch_word=strstr(srch_string,word); // ptr points to found word or 0
if(srch_word!=0) // if 0, no matches found. Otherwise..
{
i = srch_word + strlen(word); // i=end of found word
while(srch_word<i) // insert spaces where the
*srch_word++=' '; // word was so no checking twice
clean_up_str(srch_string); // remove the spaces (remove the double word)
}
}
word=strtok(0,space); // go to next word
}
return(retval);
}
// this function return the number of numbers in the string passed
// into it. For example: 123 would return 3 because there are 3 numbers.
int get_num_numbers(char *str) {
int retval;
retval=0; // initialize varialbes
while(*str!=0) // loop until all characters checked
{
if(isdigit(*str++)) // if the character is a number
retval++; // increment the counter
}
return(retval);
}
// this function allows users to enter in text, and then it calculates
// some statistics including the number of words, the number of unique
// words and the number of numbers in the user entered text.
void main() {
char input_str[STRING_SIZE];
while(TRUE)
{
printf("\n\rEnter a string of text. The maximum number of characters is %U.\n\r", STRING_SIZE-1);
get_string(input_str,STRING_SIZE); // gets the string
clean_up_str(input_str); // removes all punctuation and extra spaces
printf("\n\n\rSTATISTICS:\n\r");
printf("You entered %U word(s).\n\r", get_num_words(input_str));
printf("You entered %U unique word(s).\n\r", get_num_unique_words(input_str));
printf("You entered %U number(s).\n\r", get_num_numbers(input_str));
}
}
as unicas alterações que fiz foi o valor do cristal (que estava 20MHz no exemplo) e o microcontrolador (que estava como 16F877).
já le todos os posts no forum antigo e ainda não consegui fazer funcionar. Algumas tentativas foram:
*Mudar a velocidade do Baud rate (não fez diferença)
*Habilitar "Ecoar localmente caracteres digitados" não funcionou
*colocar fuses (não funcionou)
qualquer ajuda seria bem vinda!!!
Valeu!!!