CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

rs232 problem - SOLVED
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

rs232 problem - SOLVED
PostPosted: Tue Apr 22, 2014 12:35 am     Reply with quote

I am sending from the PIC 19 bytes that should be:
55h,AAh,16*00h,FFh
I get:
19*00h
The message is sent once a second. (enable_interrupts(INT_TBE);)
Tested with two different terminals, both same.
The program was working fine and suddenly stopped working. I made this test program to try to find out what is the problem.
Testing in MPLAB simulator, no problem.
I am using basic FTDI USB to TTL converter
CCS PCM C Compiler, Version 3.249, 37061
Help much appreciated.
Code:

///////////////////////////////////////////////////////////
#include <16F648A.h>

#FUSES WDT                   
#FUSES EC_IO
#FUSES BROWNOUT,MCLR,NOLVP,NOPROTECT,NOCPD,PUT                   
#use delay(clock=8000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,restart_wdt)
///////////////////////////////////////////////////////////////////
#int_TBE
void TBE_isr(void)
{
   restart_wdt();
   switch(scomtxwords)
   {
      case 0:
      {
         putc(0x55);
         scomtxwchs=0x55;   
         scomtxwords++;      
      }
      break;
      case 1:
      {
         putc(0xAA);
         scomtxwchs=0xFF;
         scomtxwords++;         
      }
      break;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      case 2:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 3:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 4:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 5:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 6:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 7:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 8:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 9:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 10:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 11:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 12:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 13:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 14:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 15:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 16:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 17:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      case 18:
      {
         putc(scomtxwchs);
         scomtxwords=0;   
         disable_interrupts(INT_TBE);                  
      }
      break;
   }         
}


Last edited by gjs_rsdi on Mon Apr 28, 2014 7:29 pm; edited 1 time in total
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sat Apr 26, 2014 3:47 am     Reply with quote

I have rewritten the software, same problem
Code:

#include "Scom1.h"
#include <math.h>
#include "Scom1VR.h"
#include "Scom1SC.h"

#int_TIMER0
void TIMER0_isr(void)
{
   restart_wdt();   
   timecounter++;
   if(timecounter>=60)
   {
      timecounter=0;
      enable_interrupts(INT_TBE);
   }   
}

void main()
{

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   disable_interrupts(INT_TBE);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_oscillator(False);
   while(1)
   {
         restart_wdt();
         enable_interrupts(GLOBAL);
   }
}

Scom1.h
#include <16F648A.h>

#FUSES WDT                      //Watch Dog Timer
#FUSES EC_IO   
#FUSES PUT,NOPROTECT,BROWNOUT,MCLR,NOLVP,NOCPD                 
#use delay(clock=8000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,restart_wdt)

Scom1VR.h
//---------------------------------------------------------
//serial communication tx variables------------------------
//---------------------------------------------------------
int scomtxwords=0;//scom tx switch
int scomtxwchs=0;//lsb of the check sum
//---------------------------------------------------------
//serial communication rx variables------------------------
//---------------------------------------------------------
int timecounter=0;
short scomfailflag=0;
short newsetdataflag=0;
short readdataflag=0;
short devicereadwriteflag=0;
int scomrxwords=0;//scom rx switch
int scomrxw0=0;//0x55 sinchronization byte0
int scomrxw1=0;//0xAA sinchronization byte1
int scomrxw2=0;
int scomrxw3=0;
int scomrxw4=0;
int scomrxw5=0;
int scomrxw6=0;
int scomrxw7=0;
int scomrxw8=0;
int scomrxw9=0;
int scomrxw10=0;
int scomrxw12=0;//received check sum
int scomrxwchs=0;//calculated check sum lsb
//---------------------------------------------------------

Scom1SC.h
//////////////////////////////////////////////////////////
//SCOM TX
///////////////////////////////////////////////////////////
#int_TBE
void TBE_isr(void)
{
   restart_wdt();
   switch(scomtxwords)
   {
      case 0:
      {
         putc(0x55);
         scomtxwchs=0x55;   
         scomtxwords++;      
      }
      break;
      case 1:
      {
         putc(0xAA);
         scomtxwchs=0xFF;
         scomtxwords++;         
      }
      break;
      case 2:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 3:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 4:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 5:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 6:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 7:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 8:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 9:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 10:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 11:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 12:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 13:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 14:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 15:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 16:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 17:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 18:
      {
         putc(scomtxwchs);
         scomtxwords=0;   
         disable_interrupts(INT_TBE);                  
      }
      break;
   }         
}
///////////////////////////////////////////////////////////
//SCOM RX
///////////////////////////////////////////////////////////
#int_RDA
void RDA_isr(void)
{
   restart_wdt();
   switch(scomrxwords)
   {
      case 0:
      {
         scomrxw0=getc();
         if (scomrxw0==85)
         {
            scomrxwchs=85;
            scomrxwords=1;
         }
         else
         {
            scomrxwords=0;
         }   
      }
      break;
      case 1:
      {
         scomrxw1=getc();
         if (scomrxw1==170)
         {
            scomrxwchs=255;
            scomrxwords++;
         }
         else
         {
            scomrxwords=0;
         }         
      }
      break;
      case 2:
      {
         scomrxw2=getc();
         scomrxwchs=scomrxwchs+scomrxw2;
         scomrxwords++;         
      }
      break;
      case 3:
      {
         scomrxw3=getc();
         scomrxwchs=scomrxwchs+scomrxw3;
         scomrxwords++;         
      }
      break;
      case 4:
      {
         scomrxw4=getc();
         scomrxwchs=scomrxwchs+scomrxw4;
         scomrxwords++;         
      }
      break;
      case 5:
      {
         scomrxw5=getc();
         scomrxwchs=scomrxwchs+scomrxw5;
         scomrxwords++;         
      }
      break;
      case 6:
      {
         scomrxw6=getc();
         scomrxwchs=scomrxwchs+scomrxw6;
         scomrxwords++;         
      }
      break;
      case 7:
      {
         scomrxw7=getc();
         scomrxwchs=scomrxwchs+scomrxw7;
         scomrxwords++;         
      }
      break;
      case 8:
      {
         scomrxw8=getc();
         scomrxwchs=scomrxwchs+scomrxw8;
         scomrxwords++;         
      }
      break;
      case 9:
      {
         scomrxw9=getc();
         scomrxwchs=scomrxwchs+scomrxw9;
         scomrxwords++;         
      }
      break;
      case 10:
      {
         scomrxw10=getc();
         scomrxwchs=scomrxwchs+scomrxw10;
         scomrxwords++;         
      }
      break;
      case 11:
      {
         devicereadwriteflag=getc();
         scomrxwchs=scomrxwchs+devicereadwriteflag;
         scomrxwords++;         
      }
      break;
      case 12:
      {
         scomrxw12=getc();
         if (scomrxwchs==scomrxw12)
         {
            scomfailflag=0;
            if(devicereadwriteflag==0)//if '0', device read command
            {                                             
//               readdataflag=1;
            }
            else//if '1', device write command
            {
//               newsetdataflag=1;
            }
         }
         else
         {
//            scomfailflag=1;   
         }
         scomrxwords=0;   
//         enable_interrupts(INT_TBE);   
      }
      break;
   }
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Apr 26, 2014 7:02 am     Reply with quote

I have not got a snowball in Hades chance of solving your problem.

If you want help we need short, complete, compilable code to copy. paste and test.

Your code is none of the above.

a) It's too long,
b) We don't have your Scom1.h etc.
c) No main()
.............................

Explains why you have had no response to your original post.

Mike
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sat Apr 26, 2014 10:34 pm     Reply with quote

Thanks for the attention Mike.
I shortened the program and put all the headers on the same page as the .c
I am sending now just 5 bytes.
It is compiling, working in the MPLAB simulator, working with the board, but I get: 00,00,00,00,00
instead of 55,AA,00,00,FF

Code:

//Scom1.h-----------------------------
#include <16F648A.h>

#FUSES WDT                      //Watch Dog Timer
#FUSES EC_IO   
#FUSES PUT,NOPROTECT,BROWNOUT,MCLR,NOLVP,NOCPD                 
#use delay(clock=8000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,restart_wdt)
//Scom1VR---------------------------------
int timecounter=0;
int scomtxwords=0;//scom tx switch
int scomtxwchs=0;//lsb of the check sum
//Scom1SC------------------------------
#int_TBE
void TBE_isr(void)
{
   restart_wdt();
   switch(scomtxwords)
   {
      case 0:
      {
         putc(0x55);
         scomtxwchs=0x55;   
         scomtxwords++;      
      }
      break;
      case 1:
      {
         putc(0xAA);
         scomtxwchs=0xFF;
         scomtxwords++;         
      }
      break;
      case 2:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 3:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 4:
      {
         putc(scomtxwchs);
         scomtxwords=0;   
         disable_interrupts(INT_TBE);                  
      }
      break;
   }         
}
//--------------------------------------
#int_TIMER0
void TIMER0_isr(void)
{
   restart_wdt();   
   timecounter++;
   if(timecounter>=60)
   {
      timecounter=0;
      enable_interrupts(INT_TBE);
   }   
}
//Scom1.c------------------------------
void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   disable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER0);
   disable_interrupts(INT_TBE);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_oscillator(False);
   while(1)
   {
         restart_wdt();
         enable_interrupts(GLOBAL);
   }
}

Hope it is enough clear and short.
Joe
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Sat Apr 26, 2014 11:45 pm     Reply with quote

You disable INT_TBE and enable INT_RDA, but you have the interrupt pointing to INT_TBE

Regards
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sun Apr 27, 2014 12:19 am     Reply with quote

Hi Alan

I am enabling INT_TBE ones in 2 seconds using timer0 and disable it in case 4 of the switch.
My mistake. I disable the INT_RDA but it is the same.
I am getting every 2 seconds 00,00,00,00,00

Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Sun Apr 27, 2014 12:30 am     Reply with quote

I also have to point out that on the original code, cases 2, to 17 were all the same code. As such separate code is not needed for these. When I originally saw this, I stopped looking....

On the new example, the enable_interrupts(GLOBAL), does not want to be in the loop. setup_oscillator(FALSE)!. What is this going to do?. See below.
The approach of sending a message using INT_TBE, is perfectly sensible and acceptable, but the actual writing of it is really bad. Do you really have an external clock oscillator module?. If not, the code is not going to run properly. Old comment about is you are using the hardware UART, you _must_ have ERRORS in the #use RS232. Your use of the WDT, is pointless/appalling. The key thing with a watchdog, is it only does some good, if you write the code so that the watchdog is only reset, if the chip is running correctly. Scattering 'restart' instructions round the code, means that it'll get restarted, even if the code is doing unexpected things. In which case you might as well not have the watchdog at all. Waste of code space and time.
The old key thing with debugging, is KISS. Step back, and get rid of all the interrupts, and printf a message. Do you get anything?. Anything other than '0'?. You may well have a simple hardware problem that started the code not working.
If you are going to use the watchdog, specify a divisor for it (assuming that things like this will 'default' to what you want is always dangerous). Then write the code so the watchdog _only_ gets reset if the code _is_ running properly. Get rid of all but one restart_wdt, and make sure that the code sequence _will_ reach this if the code is working, and can't if it isn't.

Your setup_oscillator(FALSE); line, may well be the problem. FALSE codes as '0', and setup_oscillator(0) will switch to about 40Khz operation....

If you say you are getting something every 2 seconds, then either his is the result of a watchdog triggering, or your oscillator is not 8MHz. Timer1, with an /8 prescaler will divide the master oscillator by 4*8*65536 = 2097152. With a counter running 0 to 60 (61 counts), you would get the interrupt being enabled every 16 seconds if your master clock was 4Mhz....
Your chip is not running at the speed you think.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sun Apr 27, 2014 1:42 am     Reply with quote

Ttelmah, thanks for the input.
I changed the program according to your advice (I hope I didn't missed something) except the timer0.
I have an 8Mhz external clock oscillator to free A6 for I/O.
I checked in the simulator, I got timer0 interrupt every 32.768ms, with the counter I am enabling the TBE approximately every 2 seconds.
While compiling, I am getting worning: Variable never used: rs232_errors.
The corected program:
Code:

//Scom1.h-----------------------------
#include <16F648A.h>

#FUSES EC_IO   
#FUSES PUT,NOPROTECT,BROWNOUT,MCLR,NOLVP,NOCPD                 
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,ERRORS)
//Scom1VR---------------------------------
int timecounter=0;
int scomtxwords=0;//scom tx switch
int scomtxwchs=0;//lsb of the check sum
//Scom1SC------------------------------
#int_TBE
void TBE_isr(void)
{
   switch(scomtxwords)
   {
      case 0:
      {
         putc(0x55);
         scomtxwchs=0x55;   
         scomtxwords++;      
      }
      break;
      case 1:
      {
         putc(0xAA);
         scomtxwchs=0xFF;
         scomtxwords++;         
      }
      break;
      case 2:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 3:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 4:
      {
         putc(scomtxwchs);
         scomtxwords=0;   
         disable_interrupts(INT_TBE);                  
      }
      break;
   }         
}
//--------------------------------------
#int_TIMER0
void TIMER0_isr(void)
{
   timecounter++;
   if(timecounter>=60)
   {
      timecounter=0;
      enable_interrupts(INT_TBE);
   }   
}
//Scom1.c------------------------------
void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   disable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER0);
   disable_interrupts(INT_TBE);
   disable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
//   setup_oscillator(False);
   while(1)
   {
      restart_wdt();
   }
}

I am still getting 00,00,00,00,00
Joe
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sun Apr 27, 2014 2:12 am     Reply with quote

Finishes testing with an other board that have a 8Mhz crystal, changed the fuse to HS but I am getting the same result.

Joe
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Apr 27, 2014 2:32 am     Reply with quote

Please confirm the following:-

1) Simple LED flasher works at the correct speed.
2) Simple "Hello World" code also operates OK.

Mike
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sun Apr 27, 2014 3:08 am     Reply with quote

I reprogrammed the software that was working before with this board.
The hardware includes an AC motor that works at 5 different speeds controlled by PWM, keyboard with 4 buttons and 5 LED's that are blinking in certain situations.
All buttons functions are correct.
LED's blinking or not, correct for the specific situations.
Motor turns in the 5 correct speeds.
Serial communication does not work. It was working before with the same software.

Joe
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sun Apr 27, 2014 3:31 am     Reply with quote

I added the LED per Mike advice to flash every second (500ms on/500ms off) and it works correct.
I didn't change the serial communication as I can read just binary on my terminals. I also don't know how to write "Hello World"
Still read 00,00,00,00,00 instead of 55,AA,00,00,FF
every 2 led flahings.
Still get: Warning 202:Variable never used: rs232_errors
Joe
Code:

//Scom1.h-----------------------------
#include <16F648A.h>

#FUSES HS   
#FUSES PUT,NOPROTECT,BROWNOUT,MCLR,NOLVP,NOCPD                 
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,ERRORS)
//Scom1VR---------------------------------
#define ledonoffout PIN_A3
int timecounter=0;
int scomtxwords=0;//scom tx switch
int scomtxwchs=0;//lsb of the check sum
//Scom1SC------------------------------
#int_TBE
void TBE_isr(void)
{
   switch(scomtxwords)
   {
      case 0:
      {
         putc(0x55);
         scomtxwchs=0x55;   
         scomtxwords++;      
      }
      break;
      case 1:
      {
         putc(0xAA);
         scomtxwchs=0xFF;
         scomtxwords++;         
      }
      break;
      case 2:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 3:
      {
         putc(0x00);
         scomtxwords++;         
      }
      break;
      case 4:
      {
         putc(scomtxwchs);
         scomtxwords=0;   
         disable_interrupts(INT_TBE);                  
      }
      break;
   }         
}
//--------------------------------------
#int_TIMER0
void TIMER0_isr(void)
{
   timecounter++;
   if((timecounter==15)||(timecounter==45))
   {
      output_high(ledonoffout);
   }
   if((timecounter==30)||(timecounter==60))
   {
      output_low(ledonoffout);
   }
   if(timecounter>=60)
   {
      timecounter=0;
      enable_interrupts(INT_TBE);
   }   
}
//Scom1.c------------------------------
void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   disable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER0);
   disable_interrupts(INT_TBE);
   disable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
//   setup_oscillator(False);
   while(1)
   {
      restart_wdt();
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Sun Apr 27, 2014 3:51 am     Reply with quote

You still have not done the basic 'hello world' test without interrupts. As I said:
"Step back, and get rid of all the interrupts, and printf a message."

You will get the rs232_errors warning. This was a stupidity by CCS, where when you add 'ERRORS' as part of the error handling code they add this variable, and if you don't use it they give this warning. Understand it is a _warning_ not an error. You can either just ignore it (what 90% of people do), or add single line to access the variable (which stops the warning), or even a dummy function to access the variable, that is never called (which stops the warning, and since it is never called, costs nothing in code...), or just tell the compiler to ignore this warning.

The simulator tells you nothing. It'll believe what you tell it about the clock, which can be wrong. You should not get an interrupt at 32768mSec, with an 8MHz clock, and T1_INTERNAL|T1_DIV_BY_8. The T1 prescaler is fed off Fosc/4. T1 counts to 65536. With an /8 prescaler the interrupt should be at 1/4 the rate you are seeing in the simulator.
Look at the timer1 block diagram in the data sheet. Note Fosc/4 when the internal source is selected. If you are seeing an interrupt at the rate you say, then it tells us something is wrong (oscillator is 32Mhz, not 8MHz, etc..).
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sun Apr 27, 2014 4:05 am     Reply with quote

Ttelmah

I am not using timer1. Using timer0.
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); with 8Mhz is giving interrupt at 32.768ms.
The LED is on for 500ms and of for 500ms with the last program.
Tested with the watch for 60 seconds.
I don't know how to printf "hello world".
I will try to learn.
Joe
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Apr 27, 2014 10:47 am     Reply with quote

Main() code fragment something like this should send "Hello World" to a PC at ~1 second intervals.

Code:
void main()
{
   while (1)
   {
      printf ("Hello World \n\r");
      delay_ms(1000);
   }
}

Your PC needs something like hyperterminal set for the same baud rate as the PIC.

I don't have your PIC, so can't do a hardware test.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group