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 CCS Technical Support

(NOT) Saving data from Bluetooth to array

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



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

(NOT) Saving data from Bluetooth to array
PostPosted: Sun Nov 15, 2020 7:49 am     Reply with quote

18F46k22

Hello.
I am trying to save the data coming via Bluetooth into an array. However, I later realized that there was a problem reading the values from the array. Tell me like this:
Code:

  unsigned int16 value=0;
  unsigned int16 dummy1=0;
  unsigned int16 dummy2=0;
  unsigned int16 array[];
  unsigned int16 k=0;
  #INT_RDA
  void serialInterrupt()
  {   
      clear_interrupt(INT_RDA);
      value=getc();

      array[k] = value;
      k++;

     delay_ms(20);                                                                   

     enable_interrupts(INT_RDA);
     enable_interrupts(GLOBAL);
}
...
...
...
while(true){
      dummy1=array[k];
      dummy2=value;
      printf("Array: %ld", dummy1);  // This line of code doesn't work
      printf("Value: %ld",dummy2);  // This line of code  work

}


I mean, when I read the value from the array, it's not the value I'm sending.
But when I directly read the value and put it on the 2nd dummy, there is no problem.

How do I fix this problem ?
Thank you
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Nov 15, 2020 7:59 am     Reply with quote

Quick comments
For starters....
See EOL comments...
1st all variables should be bytes NOT words. Data from UART will be 8 bits.

2nd 'array' has zero space allocated. Pretty sure YOU need to specify an amount, say 32 bytes for test purposes.

3rd this...

#INT_RDA
void serialInterrupt()
{
clear_interrupt(INT_RDA); //// delete this line, compiler does this
value=getc();

array[k] = value;
k++;

delay_ms(20); //// delete this line, NEVER have delays in ISRs

enable_interrupts(INT_RDA); //// delete this line, compiler does this
enable_interrupts(GLOBAL); //// delete this line, compiler does this
}

edit/recompile/test/see what happens
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Sun Nov 15, 2020 8:07 am     Reply with quote

Actually, I'd just 'disagree' with this comment:

enable_interrupts(GLOBAL); //// delete this line, compiler does this

The compiler does not do this. The _CHIP_ does this. The global
interrupt bit is disabled by the chip hardware as soon as an interrupt
handler is entered. The return from interrupt instruction automatically
re enables this bit when the interrupt exits.
It is absolutely vital on the PIC, that the global interrupt is never enabled
inside an interrupt handler. Doing so can/will result in the interrupt being
called again inside itself. Since the PIC's own hardware register saving
only supports one lot of values, if this happens, you are in a disaster.

You must never use enable_interrupts(GLOBAL) inside an interrupt handler.

Only a 'pedant mode' comment, but it is a critically important thing
about PIC interrupt handling....
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Sun Nov 15, 2020 9:06 am     Reply with quote

Thank you for your answer.
Actually, I knew my problem would not be solved since I did not share all of my code. I am not sharing it here because it is too long. But I have to share.
Before reviewing the code, please watch this short video and understand what the code will do.

[url] https://www.youtube.com/watch?v=iviJ6-IiJ10 [/url]
Actually the reason I define variables as 16 is because I don't want to drive the RGB display.

So the variables I guess the variables should remain 16 bits. Any other suggestions?

RGB.h
Code:

//satır seçimi +5V

#DEFINE p1 pin_d7
#DEFINE p2 pin_d6
#DEFINE p3 pin_d5
#DEFINE p4 pin_d4
#DEFINE p5 pin_c1
#DEFINE p6 pin_c0
#DEFINE p7 pin_a6
#DEFINE p8 pin_a7

//Kırmızı renk seçimi

#DEFINE r1 pin_b7
#DEFINE r2 pin_b6
#DEFINE r3 pin_b5
#DEFINE r4 pin_b4
#DEFINE r5 pin_b3
#DEFINE r6 pin_b2
#DEFINE r7 pin_b1
#DEFINE r8 pin_b0

//Yeşil renk seçimi

#DEFINE g1 pin_c2
#DEFINE g2 pin_c3
#DEFINE g3 pin_d0
#DEFINE g4 pin_d1
#DEFINE g5 pin_d2
#DEFINE g6 pin_d3
#DEFINE g7 pin_c4
#DEFINE g8 pin_c5

//Mabi renk seçimi

#DEFINE b1 pin_e1
#DEFINE b2 pin_e0
#DEFINE b3 pin_a5
#DEFINE b4 pin_a4
#DEFINE b5 pin_a3
#DEFINE b6 pin_a2
#DEFINE b7 pin_a1
#DEFINE b8 pin_a0


RGB.c

Code:

#include "rgb_matrix.h"

void martix_red(unsigned int16 power,unsigned int16 red ){
output_a(0x3f); output_b(0xff); output_c(0xfc); output_d(0x0f); output_e(0xff);
output_high(power);
output_low(red);

}
void martix_green(unsigned int16 power,unsigned int16 green){
output_a(0x3f); output_b(0xff); output_c(0xfc); output_d(0x0f); output_e(0xff);
output_high(power);
output_low(green);

}
void martix_blue(unsigned int16 power,unsigned int16 blue){
output_a(0x3f); output_b(0xff); output_c(0xfc); output_d(0x0f); output_e(0xff);
output_high(power);
output_low(blue);

}


Main.c

Code:

#include <18f46k22.h>
#INCLUDE <stdlib.h>
#fuses NOWDT,NOBROWNOUT,NOPUT,NOWRT,NODEBUG,INTRC_io, NOMCLR, NOPROTECT, NOWDT, NOLVP, PLLEN

#use delay(internal=64000000)                                                       

#use standard_io(a)                                                                                                                          //A portu giriş çıkış olarak kullanılacak
#use standard_io(b)                                                               
#use fast_io(c)
#use standard_io(d)
#use standard_io(e)

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#include "rgb_matrix.c"

 unsigned int16 gelenVeri=0;
 unsigned int16 satirNumarasi =0;
 unsigned int16 sutunNumarasi =0;
 unsigned int16 rgbSecim   =0;
          int16 k =0;
 unsigned int16 satir1[32];
 unsigned int16 sutun1[32];
 unsigned int16 sutunNumarasi2=0;
 unsigned int16 satirNumarasi2=0;

 
const int16 dizi_p[8]={p1,p2,p3,p4,p5,p6,p7,p8}; 
const int16 dizi_r[8]={r1,r2,r3,r4,r5,r6,r7,r8};
const int16 dizi_g[8]={g1,g2,g3,g4,g5,g6,g7,g8};
const int16 dizi_b[8]={b1,b2,b3,b4,b5,b6,b7,b8};

#int_rda //seri haberleşme kesmesi oluşturuldu
void serihaberlesme_kesmesi()
{   
clear_interrupt(INT_RDA);                                                   //kesme işlemleri yürütülürken yeni bir kesme gelmemesi için kesme kapatıldı

gelenVeri=getc();

switch (gelenVeri)
      {
         case 200: rgbSecim =1; break;
         case 201: rgbSecim =2; break;
         case 202: rgbSecim =3; break;
      }

      sutunNumarasi = (gelenVeri %8) - 1;
      satirNumarasi = gelenVeri / 8;
      if(sutunNumarasi==-1){
      sutunNumarasi = 7;
      }
      switch (gelenVeri){                    //8. Sutün için ekstra hesaplama
         case 8  : satirNumarasi = 0; break;
         case 16 : satirNumarasi = 1; break;
         case 24 : satirNumarasi = 2; break;
         case 32 : satirNumarasi = 3; break;
         case 40 : satirNumarasi = 4; break;
         case 48 : satirNumarasi = 5; break;
         case 56 : satirNumarasi = 6; break;
         case 64 : satirNumarasi = 7; break;
      }

     
      satir1[k]=satirNumarasi;
      sutun1[k]=sutunNumarasi;
      k++;



}


void main(){
setup_oscillator(OSC_64MHZ , OSC_PLL_ON);

set_tris_c(0b10111100);

output_a(0xff);
output_b(0xff);
output_c(0xff);
output_d(0xff);
output_e(0xff);

 
     
      enable_interrupts(GLOBAL);
      enable_interrupts(INT_RDA);

   while(true){
     
     // for(i=0;i<k+1;i++)
     // {
      satirNumarasi2 = satir1[k];//satirNumarasi;//
      sutunNumarasi2 = sutun1[k];//sutunNumarasi;//
     
      if(rgbSecim ==1)
      {
      martix_red(dizi_p[satirNumarasi2], dizi_r[sutunNumarasi2]);
      }
      else if(rgbSecim ==2)
      {
      martix_green(dizi_p[satirNumarasi], dizi_g[sutunNumarasi]);
      }
      else if(rgbSecim ==3)
      {
      martix_blue(dizi_p[satirNumarasi], dizi_b[sutunNumarasi]);
      }
      //}
      delay_us(50);

   }}
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Sun Nov 15, 2020 9:16 am     Reply with quote

First fix the ISR issues, and then give some space to the array you want to
store the values in,

You need something like:
Code:

  unsigned int8 value=0;
  unsigned int16 dummy1=0;
  unsigned int16 dummy2=0;
  unsigned int8 array[256]; //now you have some space....
  unsigned int16 k=0;
//Why waste space making the array int16?. The values being received
//are bytes. Single characters, not 'int16'.

#INT_RDA
void serialInterrupt()
{   
      value=getc();

      array[k] = value;
      k++;
      if (k>=256)
         k=0; //prevent overflow....                                                         
}
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Mon Nov 16, 2020 3:54 am     Reply with quote

Ttelmah wrote:
First fix the ISR issues, and then give some space to the array you want to
store the values in,

You need something like:
............

I tried the suggestion. But it didn't work. Do you have a second suggestion? Sad
Should I add something like this?
sutunNumarasi = (unsigned int8)((gelenVeri %8) - 1);
satirNumarasi = (unsigned int8)(gelenVeri / 8);
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 16, 2020 6:07 am     Reply with quote

Ok I think I understand what it is.... the PIC has direct control over 8 'power' pins and 24 ( 3 x 8 ) 'colour' pins ( RGB) that are connected to the LED display module.
A PC sends a 'data stream' with the pixel # and color information, the PIC then turns on/off the required pin of the RGB 8x8 display.

First, you do not need 16bit variables, so change to 8 bits ( bytes). The port output functions are byte width. Code using bytes is faster than words (16 bits), and speed is important with direct drive LEDs.

looking at the code as I type...
you have main() include a file called RGB_martix.h BUT have shown RGB.h !
This file is the pin assignments . Since the program compiles, the 'matrix' file must exist but perhaps it's wrong ?

also you need 'errors' added to the use RS232(...options..)

if you can post the make/model LED display, that could be helpful. I might be able to find a translated version of code, well Google might !!
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Mon Nov 16, 2020 8:47 am     Reply with quote

Thanks Temtronic. Actually, I already have a working code. You can review that code below. Since I don't want it to be too long, I try to shorten the following code with various algorithms. And yes I shortened it. The code above works fine. It only shows the current value on the matrix. It does not show previous values. So I want to apply what I did in the code below to it. Saving data in an array. If I can do that. The above code will work perfectly.
Code:

#include <18f46k22.h>
#INCLUDE <stdlib.h>
#fuses NOWDT,NOBROWNOUT,NOPUT,NOWRT,NODEBUG,INTRC_IO, NOMCLR, NOPROTECT, NOWDT, NOLVP,pllen

#use delay(internal=64000000)                                                       

#use standard_io(a)                                                                                                                                 
#use standard_io(b)                                                                 
#use fast_io(c)
#use standard_io(d)
#use standard_io(e)

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


//satır seçimi

#DEFINE p1 pin_d7
#DEFINE p2 pin_d6
#DEFINE p3 pin_d5
#DEFINE p4 pin_d4
#DEFINE p5 pin_c1
#DEFINE p6 pin_c0
#DEFINE p7 pin_a6
#DEFINE p8 pin_a7

//Kırmızı denk seçimi

#DEFINE r1 pin_b7
#DEFINE r2 pin_b6
#DEFINE r3 pin_b5
#DEFINE r4 pin_b4
#DEFINE r5 pin_b3
#DEFINE r6 pin_b2
#DEFINE r7 pin_b1
#DEFINE r8 pin_b0

//Yeşil renk seçimi

#DEFINE g1 pin_c2
#DEFINE g2 pin_c3
#DEFINE g3 pin_d0
#DEFINE g4 pin_d1
#DEFINE g5 pin_d2
#DEFINE g6 pin_d3
#DEFINE g7 pin_c4
#DEFINE g8 pin_c5

//Mabi renk seçimi

#DEFINE b1 pin_e1
#DEFINE b2 pin_e0
#DEFINE b3 pin_a5
#DEFINE b4 pin_a4
#DEFINE b5 pin_a3
#DEFINE b6 pin_a2
#DEFINE b7 pin_a1
#DEFINE b8 pin_a0

unsigned int8 valueNew;
unsigned int8 valueArray[];
unsigned int32 counter=0;
unsigned int8 valueOld=0;
unsigned int8 RGBSelect = 0;


#int_rda
void serihaberlesme_kesmesi()
{   
   clear_interrupt(INT_RDA);                                                   

   valueNew=getc();
   switch (valueNew)
      {
         case 200: RGBSelect=1; break;
         case 201: RGBSelect=2; break;
         case 202: RGBSelect=3; break;
      }
   if(valueNew!=200 && valueNew!=201 && valueNew!=202)
      {
   switch (RGBSelect)
      {
         case 1: valueNew = valueNew; break;
         case 2: valueNew = valueNew+64; break;
         case 3: valueNew = valueNew+128; break;
      }
   valueArray[counter]=valueNew;
   counter++;

}                                                               
}

   void redSelect()
   {
   switch (valueOld)
      {
         //sat1
         case 1: output_high(p1); output_low(r1); break;
         case 2: output_high(p1); output_low(r2); break;
         case 3: output_high(p1); output_low(r3); break;
         case 4: output_high(p1); output_low(r4); break;
         case 5: output_high(p1); output_low(r5); break;
         case 6: output_high(p1); output_low(r6); break;
         case 7: output_high(p1); output_low(r7); break;
         case 8: output_high(p1); output_low(r8); break;
         //sat2       
         case 9:  output_high(p2); output_low(r1); break;
         case 10: output_high(p2); output_low(r2); break;
         case 11: output_high(p2); output_low(r3); break;
         case 12: output_high(p2); output_low(r4); break;
         case 13: output_high(p2); output_low(r5); break;
         case 14: output_high(p2); output_low(r6); break;
         case 15: output_high(p2); output_low(r7); break;
         case 16: output_high(p2); output_low(r8); break;         
         //sat3
         case 17: output_high(p3); output_low(r1); break;
         case 18: output_high(p3); output_low(r2); break;
         case 19: output_high(p3); output_low(r3); break;
         case 20: output_high(p3); output_low(r4); break;
         case 21: output_high(p3); output_low(r5); break;
         case 22: output_high(p3); output_low(r6); break;
         case 23: output_high(p3); output_low(r7); break;
         case 24: output_high(p3); output_low(r8); break;         
         //sat4
         case 25: output_high(p4); output_low(r1); break;
         case 26: output_high(p4); output_low(r2); break;
         case 27: output_high(p4); output_low(r3); break;
         case 28: output_high(p4); output_low(r4); break;
         case 29: output_high(p4); output_low(r5); break;
         case 30: output_high(p4); output_low(r6); break;
         case 31: output_high(p4); output_low(r7); break;
         case 32: output_high(p4); output_low(r8); break;         
         //sat5
         case 33: output_high(p5); output_low(r1); break;
         case 34: output_high(p5); output_low(r2); break;
         case 35: output_high(p5); output_low(r3); break;
         case 36: output_high(p5); output_low(r4); break;
         case 37: output_high(p5); output_low(r5); break;
         case 38: output_high(p5); output_low(r6); break;
         case 39: output_high(p5); output_low(r7); break;
         case 40: output_high(p5); output_low(r8); break;
         //sat6
         case 41: output_high(p6); output_low(r1); break;
         case 42: output_high(p6); output_low(r2); break;
         case 43: output_high(p6); output_low(r3); break;
         case 44: output_high(p6); output_low(r4); break;
         case 45: output_high(p6); output_low(r5); break;
         case 46: output_high(p6); output_low(r6); break;
         case 47: output_high(p6); output_low(r7); break;
         case 48: output_high(p6); output_low(r8); break;
         //sat7
         case 49: output_high(p7); output_low(r1); break;
         case 50: output_high(p7); output_low(r2); break;
         case 51: output_high(p7); output_low(r3); break;
         case 52: output_high(p7); output_low(r4); break;
         case 53: output_high(p7); output_low(r5); break;
         case 54: output_high(p7); output_low(r6); break;
         case 55: output_high(p7); output_low(r7); break;
         case 56: output_high(p7); output_low(r8); break; 
         //sat8
         case 57: output_high(p8); output_low(r1); break;
         case 58: output_high(p8); output_low(r2); break;
         case 59: output_high(p8); output_low(r3); break;
         case 60: output_high(p8); output_low(r4); break;
         case 61: output_high(p8); output_low(r5); break;
         case 62: output_high(p8); output_low(r6); break;
         case 63: output_high(p8); output_low(r7); break;
         case 64: output_high(p8); output_low(r8); break;           
      }
   }
   void greenSelect()
   {
   //output_a(0x3f); output_b(0xff); output_c(0xfc); output_d(0x0f); output_e(0xff);
   switch (valueOld)
      {
         //sat1
         case 65: output_high(p1); output_low(g1); break;
         case 66: output_high(p1); output_low(g2); break;
         case 67: output_high(p1); output_low(g3); break;
         case 68: output_high(p1); output_low(g4); break;
         case 69: output_high(p1); output_low(g5); break;
         case 70: output_high(p1); output_low(g6); break;
         case 71: output_high(p1); output_low(g7); break;
         case 72: output_high(p1); output_low(g8); break;
         //sat2       
         case 73: output_high(p2); output_low(g1); break;
         case 74: output_high(p2); output_low(g2); break;
         case 75: output_high(p2); output_low(g3); break;
         case 76: output_high(p2); output_low(g4); break;
         case 77: output_high(p2); output_low(g5); break;
         case 78: output_high(p2); output_low(g6); break;
         case 79: output_high(p2); output_low(g7); break;
         case 80: output_high(p2); output_low(g8); break;         
         //sat3
         case 81: output_high(p3); output_low(g1); break;
         case 82: output_high(p3); output_low(g2); break;
         case 83: output_high(p3); output_low(g3); break;
         case 84: output_high(p3); output_low(g4); break;
         case 85: output_high(p3); output_low(g5); break;
         case 86: output_high(p3); output_low(g6); break;
         case 87: output_high(p3); output_low(g7); break;
         case 88: output_high(p3); output_low(g8); break;         
         //sat4
         case 89: output_high(p4); output_low(g1); break;
         case 90: output_high(p4); output_low(g2); break;
         case 91: output_high(p4); output_low(g3); break;
         case 92: output_high(p4); output_low(g4); break;
         case 93: output_high(p4); output_low(g5); break;
         case 94: output_high(p4); output_low(g6); break;
         case 95: output_high(p4); output_low(g7); break;
         case 96: output_high(p4); output_low(g8); break;         
         //sat5
         case 97:  output_high(p5); output_low(g1); break;
         case 98:  output_high(p5); output_low(g2); break;
         case 99:  output_high(p5); output_low(g3); break;
         case 100: output_high(p5); output_low(g4); break;
         case 101: output_high(p5); output_low(g5); break;
         case 102: output_high(p5); output_low(g6); break;
         case 103: output_high(p5); output_low(g7); break;
         case 104: output_high(p5); output_low(g8); break;
         //sat6
         case 105: output_high(p6); output_low(g1); break;
         case 106: output_high(p6); output_low(g2); break;
         case 107: output_high(p6); output_low(g3); break;
         case 108: output_high(p6); output_low(g4); break;
         case 109: output_high(p6); output_low(g5); break;
         case 110: output_high(p6); output_low(g6); break;
         case 111: output_high(p6); output_low(g7); break;
         case 112: output_high(p6); output_low(g8); break;
         //sat7
         case 113: output_high(p7); output_low(g1); break;
         case 114: output_high(p7); output_low(g2); break;
         case 115: output_high(p7); output_low(g3); break;
         case 116: output_high(p7); output_low(g4); break;
         case 117: output_high(p7); output_low(g5); break;
         case 118: output_high(p7); output_low(g6); break;
         case 119: output_high(p7); output_low(g7); break;
         case 120: output_high(p7); output_low(g8); break; 
         //sat8
         case 121: output_high(p8); output_low(g1); break;
         case 122: output_high(p8); output_low(g2); break;
         case 123: output_high(p8); output_low(g3); break;
         case 124: output_high(p8); output_low(g4); break;
         case 125: output_high(p8); output_low(g5); break;
         case 126: output_high(p8); output_low(g6); break;
         case 127: output_high(p8); output_low(g7); break;
         case 128: output_high(p8); output_low(g8); break;           
      }
   }   
void blueSelect()
   {
   //output_a(0x3f); output_b(0xff); output_c(0xfc); output_d(0x0f); output_e(0xff);
   switch (valueOld)
      {
         //sat1
         case 129: output_high(p1); output_low(b1); break;
         case 130: output_high(p1); output_low(b2); break;
         case 131: output_high(p1); output_low(b3); break;
         case 132: output_high(p1); output_low(b4); break;
         case 133: output_high(p1); output_low(b5); break;
         case 134: output_high(p1); output_low(b6); break;
         case 135: output_high(p1); output_low(b7); break;
         case 136: output_high(p1); output_low(b8); break;
         //sat2       
         case 137: output_high(p2); output_low(b1); break;
         case 138: output_high(p2); output_low(b2); break;
         case 139: output_high(p2); output_low(b3); break;
         case 140: output_high(p2); output_low(b4); break;
         case 141: output_high(p2); output_low(b5); break;
         case 142: output_high(p2); output_low(b6); break;
         case 143: output_high(p2); output_low(b7); break;
         case 144: output_high(p2); output_low(b8); break;         
         //sat3
         case 145: output_high(p3); output_low(b1); break;
         case 146: output_high(p3); output_low(b2); break;
         case 147: output_high(p3); output_low(b3); break;
         case 148: output_high(p3); output_low(b4); break;
         case 149: output_high(p3); output_low(b5); break;
         case 150: output_high(p3); output_low(b6); break;
         case 151: output_high(p3); output_low(b7); break;
         case 152: output_high(p3); output_low(b8); break;         
         //sat4
         case 153: output_high(p4); output_low(b1); break;
         case 154: output_high(p4); output_low(b2); break;
         case 155: output_high(p4); output_low(b3); break;
         case 156: output_high(p4); output_low(b4); break;
         case 157: output_high(p4); output_low(b5); break;
         case 158: output_high(p4); output_low(b6); break;
         case 159: output_high(p4); output_low(b7); break;
         case 160: output_high(p4); output_low(b8); break;         
         //sat5
         case 161: output_high(p5); output_low(b1); break;
         case 162: output_high(p5); output_low(b2); break;
         case 163: output_high(p5); output_low(b3); break;
         case 164: output_high(p5); output_low(b4); break;
         case 165: output_high(p5); output_low(b5); break;
         case 166: output_high(p5); output_low(b6); break;
         case 167: output_high(p5); output_low(b7); break;
         case 168: output_high(p5); output_low(b8); break;
         //sat6
         case 169: output_high(p6); output_low(b1); break;
         case 170: output_high(p6); output_low(b2); break;
         case 171: output_high(p6); output_low(b3); break;
         case 172: output_high(p6); output_low(b4); break;
         case 173: output_high(p6); output_low(b5); break;
         case 174: output_high(p6); output_low(b6); break;
         case 175: output_high(p6); output_low(b7); break;
         case 176: output_high(p6); output_low(b8); break;
         //sat7
         case 177: output_high(p7); output_low(b1); break;
         case 178: output_high(p7); output_low(b2); break;
         case 179: output_high(p7); output_low(b3); break;
         case 180: output_high(p7); output_low(b4); break;
         case 181: output_high(p7); output_low(b5); break;
         case 182: output_high(p7); output_low(b6); break;
         case 183: output_high(p7); output_low(b7); break;
         case 184: output_high(p7); output_low(b8); break; 
         //sat8
         case 185: output_high(p8); output_low(b1); break;
         case 186: output_high(p8); output_low(b2); break;
         case 187: output_high(p8); output_low(b3); break;
         case 188: output_high(p8); output_low(b4); break;
         case 189: output_high(p8); output_low(b5); break;
         case 190: output_high(p8); output_low(b6); break;
         case 191: output_high(p8); output_low(b7); break;
         case 192: output_high(p8); output_low(b8); break;           
      }
   } 

unsigned int32 i=0;
void main(){
   setup_oscillator(OSC_64MHZ , OSC_PLL_ON);
   set_tris_c(0b10111100);

   output_a(0xff);
   output_b(0xff);
   output_c(0xff);
   output_d(0xff);
   output_e(0xff);

   enable_interrupts(GLOBAL);                                                   
   enable_interrupts(int_rda);

   while(true){

     
      for(i=0;i<counter+1;i++)
      {
         valueOld=valueArray[i];
         output_a(0x3f); output_b(0xff); output_c(0xfc); output_d(0x0f); output_e(0xff);
         redSelect();
         greenSelect();
         blueSelect();

      }
         
   }}
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon Nov 16, 2020 8:54 am     Reply with quote

One comment though.
This:

clear_interrupt(INT_RDA);

is completely pointless....

You _cannot_ clear INT_RDA, until the character is read from the UART.
So all this does is waste an instruction. The compiler itself automatically
clears interrupts when the ISR is exited (unless you specify 'NOCLEAR'),
so it is just a waste....
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Mon Nov 16, 2020 9:08 am     Reply with quote

Thank you Ttelmah
I care about your comments. These small fixes get me closer to writing professional code. Please tell me if there is any other error. Otherwise I'll keep making small mistakes forever :(
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