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

!!! #int rda not works in device !!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hubble



Joined: 11 Dec 2006
Posts: 10

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

!!! #int rda not works in device !!!
PostPosted: Tue Jul 08, 2008 12:46 pm     Reply with quote

This is the program "running string"
Code:
#include <16F876a.h>
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP         
#use delay(clock=20000000)
#USE RS232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
         
#include <H:\Drivers\74595.c> 
#include <H:\table\row8.c> 

//###########################################################################         
#bit T0IF = 0xb.2                         

//Global variable                                                                     
int8 strobRow=0b01111111; 
int8 dataRow[8][2];                                    
int8 dataRowBuff[2];                                                             
int8 numberEEPROM=0; 
int8 sText1[70];
int8 sText2[70];
int8 sText3[60];
int8 speed=3;   
int8 column;                     
int8 row;

int8 flagShift=1;                                       
int8 litera;
//***************************************************************************
//Prototypes function                                       
void write_big_array(int index,int data);   
int read_big_array(int index);
//ППППППППППППППППППППППППППППППППППППППППППППППППППППППППППППППППППППППППППП       
#int_rda       
void Interrupt_RS232()                     
{                                                             
//Local variable     
int8 lenght=0;
int8 value;
int8 i;
//************************* 
   while(value!='\n')
   {
        value=getc();       
      if(value!='\n'){   
         write_big_array(lenght,value);
         lenght++;
      }
      else{
         for(i=0;i<lenght;i++)
            write_eeprom(i,read_big_array(i));          
         write_eeprom(255,lenght);
      }
   }
   //*************************
   column=0;row=0;
   strobRow=0b01111111;
   numberEEPROM=0;
   flagShift=1;
   T0IF=0;
   set_rtcc(100);
}
//***************************************************************************                           
#int_rtcc                                                   
void Interrupt_RTCC()                               
{                                                                               
//Local variable       
int8 sign;
int8 repeat;         
//*************************   
   rotate_left(&strobRow,1);                                    
      
   if(flagShift){
      if(litera<=31)            
         shift_left(dataRow[row],2,bit_test(SingNumber[8*litera+7-row],7-column));
      if((litera>=160)&&(litera<=191))
         shift_left(dataRow[row],2,bit_test(literaBig[8*litera+7-row],7-column));
      if((litera>=192)&&(litera<=223))      
         shift_left(dataRow[row],2,bit_test(literaSmall[8*litera+7-row],7-column));
   }
                  
   for(sign=0;sign<2;sign++)
      dataRowBuff[sign]=dataRow[row][sign];   
      
   output_b(0xff);         
   write_expanded_outputs(dataRowBuff); 
   output_b(strobRow);

     row++;
   if(row>7){                                       
      row=0;
      flagShift=0;   
      repeat++;
      if(repeat>speed){      
           repeat=0;
           flagShift=1;
         column++;   
         if(column>7){
            column=0;
            numberEEPROM++;
            if(numberEEPROM>read_eeprom(255)-1)
               numberEEPROM=0;
         }
      }
   }
   set_rtcc(100);
}                                                 
//###########################################################################
void main()                                                                                                             
{                                                         
//************************* 
enable_interrupts(GLOBAL);
enable_interrupts(int_rda);
enable_interrupts(int_rtcc);                                         
setup_counters(rtcc_internal,rtcc_div_64|rtcc_8_bit);
//*************************   
   set_rtcc(100);
   column=0;row=0;
   litera=read_eeprom(numberEEPROM)-' ';

   while(true){                                             
      litera=read_eeprom(numberEEPROM)-' ';      
      delay_us(100);
     }
}             
//###########################################################################   
int8 index;

void write_big_array(int index,int data)
{
    if(index<70)
        sText1[index]=data;
    else if(index<140) 
        sText2[index-70]=data;
    else
        sText3[index-140]=data;         
}

int read_big_array(int index)
{
    if(index<70)
        return(sText1[index]);
    else if(index<140) 
        return(sText2[index-70]);
    else
        return(sText3[index-140]);       
}


row8.c file:


const int8 SingNumber[256]={
                           0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // SPACE
                           0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x10, // !
                           0x28,0x28,0x28,0x00,0x00,0x00,0x00,0x00, // "
                           0x28,0x28,0xfe,0x28,0xfe,0x28,0x28,0x00, // #
                           0x7c,0xaa,0xa8,0x7c,0x2a,0x2a,0xaa,0x7c, // $
                           0xe0,0xa2,0xe4,0x08,0x10,0x2e,0x4a,0x8e, // %
                           0xe2,0xa4,0xe8,0x10,0x2e,0x4a,0x8e,0x00, // &
                           0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00, // '
                           0x10,0x20,0x40,0x40,0x40,0x40,0x20,0x10, // (
                           0x10,0x08,0x04,0x04,0x04,0x04,0x08,0x10, // )
                           0x10,0x10,0x7c,0x28,0x44,0x00,0x00,0x00, // *
                           0x10,0x10,0x10,0xfe,0x10,0x10,0x10,0x00, // +
                           0x00,0x00,0x00,0x00,0x18,0x18,0x08,0x10, // ,
                           0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00, // -
                           0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18, // .
                           0x04,0x08,0x08,0x10,0x10,0x20,0x20,0x40, // /
                           0x7c,0x82,0x86,0x8a,0x92,0xa2,0xc2,0x7c, // 0
                           0x10,0x30,0x50,0x10,0x10,0x10,0x10,0x7c, // 1
                           0x7c,0x82,0x02,0x02,0x3c,0x40,0x80,0xfe, // 2
                           0x7c,0x82,0x02,0x0c,0x02,0x02,0x82,0x7c, // 3
                           0x04,0x0c,0x14,0x24,0x44,0xfe,0x04,0x04, // 4
                           0xfe,0x80,0x80,0xfc,0x02,0x02,0x82,0x7c, // 5
                           0x7c,0x82,0x80,0xfc,0x82,0x82,0x82,0x7c, // 6
                           0xfe,0x02,0x04,0x08,0x10,0x10,0x10,0x10, // 7
                           0x7c,0x82,0x82,0x7c,0x82,0x82,0x82,0x7c, // 8
                           0x7c,0x82,0x82,0x82,0x7e,0x02,0x82,0x7c, // 9
                           0x00,0x18,0x18,0x00,0x18,0x18,0x00,0x00, // :
                           0x00,0x18,0x18,0x00,0x18,0x18,0x08,0x10, // ;
                           0x10,0x20,0x40,0x80,0x40,0x20,0x10,0x00, // <
                           0x00,0x00,0xfe,0x00,0xfe,0x00,0x00,0x00, // =
                           0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x00, // >
                           0x7c,0x82,0x02,0x02,0x0c,0x10,0x00,0x10};// ?
int8 const literaBig[256]={
                           0x38,0x44,0x82,0x82,0xfe,0x82,0x82,0x82,   //А
                           0xfe,0x80,0x80,0xfc,0x82,0x82,0x82,0xfc,   //Б                                                                         
                           0xfc,0x82,0x82,0xfc,0x82,0x82,0x82,0xfc,   //В                                                                         
                           0xfe,0x80,0x80,0x80,0x80,0x80,0x80,0x80,   //Г                                                                       
                           0x3c,0x44,0x44,0x44,0x44,0x44,0xfe,0x82,   //Д
                           0xfe,0x80,0x80,0xf8,0x80,0x80,0x80,0xfe,   //Е
                             0x92,0x92,0x54,0x38,0x54,0x92,0x92,0x92,   //Ж                                                                                      
                             0x7c,0x82,0x02,0x3c,0x02,0x02,0x82,0x7c,   //З 
                             0x82,0x82,0x86,0x8a,0x92,0xa2,0xc2,0x82,   //И
                             0xba,0x82,0x86,0x8a,0x92,0xa2,0xc2,0x82,   //Й           
                           0x84,0x88,0x90,0xe0,0x90,0x88,0x84,0x82,   //К                                                                                                                                                                                                                                                                                                                                                                                        
                             0x3e,0x42,0x42,0x42,0x42,0x42,0x42,0x82,   //Л                   
                             0x82,0xc6,0xaa,0x92,0x92,0x82,0x82,0x82,   //М
                             0x82,0x82,0x82,0xfe,0x82,0x82,0x82,0x82,   //Н
                             0x7c,0x82,0x82,0x82,0x82,0x82,0x82,0x7c,   //О
                             0xfe,0x82,0x82,0x82,0x82,0x82,0x82,0x82,   //П                                             
                             0xfc,0x82,0x82,0x82,0xfc,0x80,0x80,0x80,   //Р                         
                             0x7c,0x82,0x80,0x80,0x80,0x80,0x82,0x7c,   //С     
                             0xfe,0x10,0x10,0x10,0x10,0x10,0x10,0x10,   //Т           
                             0x82,0x82,0x82,0x7e,0x02,0x02,0x82,0x7c,   //У
                             0x7c,0x92,0x92,0x92,0x92,0x92,0x7c,0x10,   //Ф
                             0x82,0x44,0x28,0x10,0x28,0x44,0x82,0x82,   //Х
                             0x84,0x84,0x84,0x84,0x84,0x84,0xfe,0x02,   //Ц
                             0x82,0x82,0x82,0x82,0x7e,0x02,0x02,0x02,   //Ч                 
                             0x82,0x82,0x92,0x92,0x92,0x92,0x92,0xfe,   //Ш
                             0x82,0x82,0x92,0x92,0x92,0x92,0xfe,0x02,   //Щ
                             0xc0,0x40,0x40,0x7c,0x42,0x42,0x42,0x7c,   //Ъ                                             
                             0x82,0x82,0x82,0xf2,0x8a,0x8a,0x8a,0xf2,   //Ы
                             0x80,0x80,0x80,0xfc,0x82,0x82,0x82,0xfc,   //Ь                 
                             0x78,0x84,0x02,0x7e,0x02,0x02,0x84,0x78,   //Э
                             0x9c,0xa2,0xa2,0xe2,0xa2,0xa2,0xa2,0x9c,   //Ю   
                             0x7e,0x82,0x82,0x82,0x7e,0x12,0x22,0xc2}; //Я   
                                                
int8 const literaSmall[256]={         
                           0x00,0x00,0x7c,0x02,0x7a,0x86,0x86,0x7a,   //а
                           0x00,0x00,0xfe,0x80,0xfc,0x82,0x82,0xfc,   //б
                             0x00,0x00,0xfc,0x82,0xfc,0x82,0x82,0xfc,  //в                                                                 
                             0x00,0x00,0xfe,0x80,0x80,0x80,0x80,0x80,  //г                                                               
                             0x00,0x00,0x3c,0x44,0x44,0x44,0xfe,0x82,  //д                                                                 
                             0x00,0x00,0x7c,0x82,0xfe,0x80,0x82,0x7c,  //е                                                                          
                             0x00,0x00,0x92,0x54,0x38,0x38,0x54,0x92,  //ж
                             0x00,0x00,0x7c,0x82,0x3c,0x02,0x82,0x7c,  //з   
                             0x00,0x00,0x82,0x86,0x8a,0x92,0xa2,0xc2,  //и
                             0x00,0x00,0x92,0x86,0x8a,0x92,0xa2,0xc2,  //й
                             0x00,0x00,0x8c,0x90,0xe0,0x90,0x88,0x86,  //к
                             0x00,0x00,0x3e,0x42,0x42,0x42,0x42,0x82,  //л
                             0x00,0x00,0x82,0xc6,0xaa,0x92,0x82,0x82,  //м
                             0x00,0x00,0x82,0x82,0xfe,0x82,0x82,0x82,  //н       
                             0x00,0x00,0x7c,0x82,0x82,0x82,0x82,0x7c,  //о   
                             0x00,0x00,0xfe,0x82,0x82,0x82,0x82,0x82,  //п   
                             0x00,0x00,0xfc,0x82,0x82,0xfc,0x80,0x80,  //р
                             0x00,0x00,0x7c,0x82,0x80,0x80,0x82,0x7c,  //с
                             0x00,0x00,0xfe,0x10,0x10,0x10,0x10,0x10,  //т
                             0x00,0x00,0x82,0x82,0x7e,0x02,0x82,0x7c,  //у
                             0x00,0x00,0x10,0x7c,0x92,0x92,0x7c,0x10,  //ф
                             0x00,0x00,0x82,0x44,0x28,0x10,0x28,0xc6,  //х   
                           0x00,0x00,0x84,0x84,0x84,0x84,0xfe,0x02,  //ц
                           0x00,0x00,0x82,0x82,0x82,0x7e,0x02,0x02,  //ч
                           0x00,0x00,0x82,0x82,0x92,0x92,0x92,0xfe,  //ш
                           0x00,0x00,0x82,0x92,0x92,0x92,0xfe,0x02,  //щ
                           0x00,0x00,0xc0,0x40,0x7c,0x42,0x42,0x7c,  //ъ
                           0x00,0x00,0x82,0x82,0xf2,0x8a,0x8a,0xf2,  //ы
                           0x00,0x00,0x80,0x80,0xfc,0x82,0x82,0xfc,  //ь
                           0x00,0x00,0x7c,0x82,0x3e,0x02,0x84,0x78,  //э
                           0x00,0x00,0x9c,0xa2,0xe2,0xa2,0xa2,0x9c,  //ю
                           0x00,0x00,0x7e,0x82,0x82,0x7e,0x22,0xc2}; //я



74595.c file:


#IFNDEF EXP_OUT_ENABLE
                           
#define EXP_OUT_DO      PIN_C3                           
#define EXP_OUT_ENABLE  PIN_C4             
#define EXP_OUT_CLOCK   PIN_C5
#define NUMBER_OF_74595 12
                                         
#ENDIF                                                                           
                                   
                                                     
void write_expanded_outputs(int8* eo) {
  int8 i;                                           
                                               
  output_low(EXP_OUT_CLOCK);                                                       
  output_low(EXP_OUT_ENABLE);
                                           
  for(i=1;i<=NUMBER_OF_74595*8;++i) {  // Clock out bits to the eo array
    if((*(eo+(NUMBER_OF_74595-1))&0x80)==0)
      output_low(EXP_OUT_DO); 
    else                                   
      output_high(EXP_OUT_DO);       
   shift_left(eo,NUMBER_OF_74595,0);     
   output_high(EXP_OUT_CLOCK);
   output_low(EXP_OUT_CLOCK);
  }
  output_high(EXP_OUT_ENABLE);             
  output_low(EXP_OUT_ENABLE);

}                           

This program NOT works in device (but ONLY in PROTEUS). If I comment #int rda procedure (or next line //enable_interrupts(int_rda);) that program works both in PROTEUS and in device.
What I doing not correct? Help me, please, in my problem.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 08, 2008 1:36 pm     Reply with quote

The design of your rda isr is not the best.

You should change it so you only get one character per interrupt.
Don't sit inside the rda isr and wait in a loop to get all the chars.
Also, don't write to the eeprom inside the rda isr.

When you get the "end of string" character (\n), then set a global
flag in the isr code. In the while() loop in main(), you should poll
the global flag. If it's set, then write the buffer to eeprom. Then
clear the flag. This method assumes that there is enough time
between the incoming strings for you to write the entire string to
eeprom, before a new string arrives. Remember, it takes typically
4 ms to write to one byte of eeprom. But the RS-232 characters
come in at a rate of 1 ms per byte. You can't handle two or more
strings coming in quickly, with only a short gap between the strings.
You need enough time to write the string to eeprom.

Also, add the statements shown in bold below:
Quote:
#include <16F876a.h>
#DEVICE(WRITE_EEPROM=ASYNC)
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#USE RS232(baud=9600,xmit=PIN_C6,rcv=PIN_C7, ERRORS)

The #device line prevents the compiler from disabling interrupts
during the 4 ms delay when the eeprom is being written.
The ERRORS parameter prevents the UART from locking up if you
are not able to get the characters quickly enough.
hubble



Joined: 11 Dec 2006
Posts: 10

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

hubble
PostPosted: Tue Jul 08, 2008 2:56 pm     Reply with quote

Thank For useful advices and explanations. Try to correct mistakes, which you have prompted. But problem appears before receiving bytes.

I try to explain my problems:
1. I use program from this post (COMMENTING #int rda procedure).
2. This is works (in PROTEUS and in working device). I have "running string". This is letter 'я' in russian. In ASCII code - 0xFF='я'.
3. ...
4. I UNCOMMENTING #int rda procedure.
5. This is works in PROTEUS, but NOT works in working device. I until do not receiving bytes through RS232, but line already does NOT run.
6. I have not "running string" in matrix.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jul 08, 2008 4:20 pm     Reply with quote

I would suggest you start very basic. This is usually the best thing to do.

Create only a simple main() and a very basic #int_rda() that will capture one character and echo it back to the PC. Once you have that working then try to capture a few characters, one at a time - meaning, enter the ISR, do a getc(), stuff it in an array and then exit the ISR. Do this a few times and then spit the array back out to the PC and see if it's intact.

Once you get this working then build upon that until you get the results you want. It's sometimes best to start extremely basic, doing one thing at a time, and then build upon the successes you have.

Ronald
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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