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

Problem in use PORTB PIC 16F876A

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



Joined: 16 Feb 2014
Posts: 4

View user's profile Send private message

Problem in use PORTB PIC 16F876A
PostPosted: Sun Feb 16, 2014 1:41 pm     Reply with quote

i use ccs c compiler
the compiler indicate 0 error I transfer the hex file to proteus but nothing happened at the PORTB also when i use mplabsim nothing happed either at PORTB plz help me this is the code:
code:
#include <16F876A.h>
#include <float.h>
#include <math.h>
//#device *=16 ADC=8 //16bit pointer, 8-bit ADC
#use delay(clock=20000000)
#fuses HS,NOWDT,NOPROTECT,PUT,NOWRT,B ROWNOUT,NOLVP
#define TRISA 0b00000000
#define TRISB 0b00000000
#define TRISC 0b00000000
#define Port_Ai 0b00000000 //Initial valua for Port A
#define Port_Bi 0b00000000 //Initial valua for Port B
#define Port_Ci 0b00000000 //Initial valua for Port C
typedef struct {
int1 bit0;
int1 bit1;
int1 bit2;
int1 bit3;
int1 bit4;
int1 bit5;
int1 bit6;
int1 bit7;
} flags;
//Important time variables
float ts, ta, tb, t0, tmag; //time related variable
//Important phase variables
float phase, phaset1; //to identify sector number
float phaset2, thetha, thetha1, thetha2; //to calculate related time variables
float modin; //modulation index
float ZZ; //to convert angles larger than 360 degrees into the scale of 0 to 360 degrees
//Important voltage related variables
float vref, vdc; //to calculate modulation index
//Other variables
int8 i, j, h; //counter
float nsamp, result1; //condition for one complete cycle
int8 n; //sector number
//Variables for Rounding up Process
float result, integral, integral1, XX; // variables for rounding up process
int8 YY, integral2;
float testa1;
//Interrupt Bit
flags sys01;
#define flg_10ms sys01.bit0
//Arrays of Outputs of Each Sector (1 to 6)
int8
outta1[8]={0b00000000,0b00000100,0b0000 0110,0b00000111,0b00000111,0b0 0000110,0b00000100,
0b00000000}; //test mar
int8
outta2[8]={0b00000000,0b00000010,0b0000 0110,0b00000111,0b00000111,0b0 0000110,0b00000010,
0b00000000}; //test mar
int8
outta3[8]={0b00000000,0b00000010,0b0000 0011,0b00000111,0b00000111,0b0 0000011,0b00000010,
0b00000000}; //test mar
int8
outta4[8]={0b00000000,0b00000001,0b0000 0011,0b00000111,0b00000111,0b0 0000011,0b00000001,
0b00000000}; //test mar
int8
outta5[8]={0b00000000,0b00000001,0b0000 0101,0b00000111,0b00000111,0b0 0000101,0b00000101,
0b00000000}; //test mar
int8
outta6[8]={0b00000000,0b00000100,0b0000 0101,0b00000111,0b00000111,0b0 0000101,0b00000100,
0b00000000}; //test mar
int8 timema[8];
//Initialization
void init(){
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
// enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
}
//Function to transfer output from array to output port
void showout(){

if(n == 1)
{
for(j=0;j<8;j++)
{
output_b(outta1[j]);
delay_ms(timema[j]);
}
}
if(n == 2)
{
for(j=0;j<8;j++)
{
output_b(outta2[j]);
delay_ms(timema[j]);
}
}
if(n == 3)
{
for(j=0;j<8;j++)
{
output_b(outta3[j]);
delay_ms(timema[j]);
}
}
if(n == 4)
{
for(j=0;j<8;j++)
{
output_b(outta4[j]);
delay_ms(timema[j]);
}
}
if(n == 5)
{
for(j=0;j<8;j++)
{
output_b(outta5[j]);
delay_ms(timema[j]);
}
}
if(n == 6)
{
for(j=0;j<8;j++)
{
output_b(outta6[j]);
delay_ms(timema[j]);
}
}
}

//Function to round up ta, tb and t0
void roundup()
{
result=modf(XX,&integral);
YY = integral;
if ((result >=0) && (result <0.5))
{
YY = YY + 0;
}
else{
if ((result >= 0.5) && (result < 1))
{
YY = YY + 1;
}
}
}
//Function to identifying sector number
void idsec()
{
for(i=1;i<=6;i++)
{
phaset1 = i*3.142/3;
phaset1 = phaset1 - phase;
phaset2 = phase - (i - 1)*3.142/3;
if((phaset1 >=0) && (phaset2 >=0))
{
n = i;
}
}
}
//Function to collect and re-insert rounded up numbers for important time variables
void rdjob()
{
XX = ta;
roundup();
ta = YY;
XX = tb;
roundup();
tb = YY;
XX = t0;
roundup();
t0 = YY;
}
//Function to obtain input details
void in_put()
{
vdc = 10;
vref = 10;
//fundamental frequency of 10 Hz (100 samples)
phase = 2*3.142*h*0.01;
}
// Calculation of time ta, tb, ts and t0
void tcal()
{
ts = 1000/100;
thetha = phase;
thetha1 = (n*3.142/3) - thetha;
thetha2 = thetha - (n - 1)*3.142/3;
tmag = (sqrt(3))*(modin)*ts/4; //moin=vref1/vdc1
ta = (tmag)*(sin(thetha1)); //test time
tb = (tmag)*(sin(thetha2)); //test time
t0 = ts - ta - tb;
t0 = t0/2;
rdjob();
//Putting times into timema array
timema[0]=t0;
timema[3]=t0;
timema[4]=t0;
timema[7]=t0;
timema[1]=ta;
timema[6]=ta;
timema[2]=tb;
timema[5]=tb;
}
//Main function
void main()
{
Mainloop:

nsamp = 100;

result1=modf(nsamp,&integral1) ;

integral2=integral1+1;

h=1;
do
{

in_put();
idsec();
tcal();
h++;
} while (h < integral2);

goto Mainloop;

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 2:18 pm     Reply with quote

1) Learn to use the code buttons.
2) Generally avoid Goto. Considered 'bad practice' in any modern language. Dangerous, since it doesn't ensure the stack is kept balanced.
3) Use a switch case, for all the tests.
4) You never call the output function, init function etc.. Simple reason for no output, is the code never outputs....
Mike Walne



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

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 2:25 pm     Reply with quote

1) Get rid of Proteus.
2) Use REAL hardware.
3) Reduce your code to 10 - 20 lines to show the problem you're having.
4) Read the forum guidelines.
5) Learn to use the code button.

Mike

EDIT Ttelmah got in again as I typed.
Been to grandson's 18th so I have a good excuse.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 2:34 pm     Reply with quote

and as one more comment, all the showout routines could be replaced by one, if you use a two dimensional array.

Messy code <> reliable code.

Guess what you have.....
ichigo295



Joined: 16 Feb 2014
Posts: 4

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 2:56 pm     Reply with quote

plz Ttelmah how to call the output function,
Mike Walne



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

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 3:12 pm     Reply with quote

Reduce code to a manageble size then we can begin.
Get it all to fit within a screenful.
Simply highlight the section which is causing problems, ignore the rest for now.
I don't care to wade through pages of irrelevant material.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 3:21 pm     Reply with quote

and, get a basic C textbook.

How to call a function, will be covered in it.
ichigo295



Joined: 16 Feb 2014
Posts: 4

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 3:21 pm     Reply with quote

Code:
//Function to transfer output from array to output port
void showout(){

if(n == 1)
{
for(j=0;j<8;j++)
{
output_b(outta1[j]);
delay_ms(timema[j]);
}
}
if(n == 2)
{
for(j=0;j<8;j++)
{
output_b(outta2[j]);
delay_ms(timema[j]);
}
}
if(n == 3)
{
for(j=0;j<8;j++)
{
output_b(outta3[j]);
delay_ms(timema[j]);
}
}
if(n == 4)
{
for(j=0;j<8;j++)
{
output_b(outta4[j]);
delay_ms(timema[j]);
}
}
if(n == 5)
{
for(j=0;j<8;j++)
{
output_b(outta5[j]);
delay_ms(timema[j]);
}
}
if(n == 6)
{
for(j=0;j<8;j++)
{
output_b(outta6[j]);
delay_ms(timema[j]);
}
}
}
[b]
this is output function how to call it in the  programme
ichigo295



Joined: 16 Feb 2014
Posts: 4

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 3:24 pm     Reply with quote

this is output function how to call it in the programme
hhhhhhhhh i know now how to use code button
temtronic



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

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 3:40 pm     Reply with quote

When you post a reply, you'll see a 'Subject ' line, then a 'Message body' line.
In the message body line are several 'buttons' of options.
Where you want to include your program code click on [code],then insert your code( ctrl V to paste), then click on [code] again.
Magically when that reply is read , your code 'looks better' !!
Don't ask me how or why,I just know it does.
The key thing is then smaller the code, the faster someone can figure out what's going on.Using the [code] button makes the code look like code.

hth
jay
Mike Walne



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

View user's profile Send private message

PostPosted: Sun Feb 16, 2014 5:39 pm     Reply with quote

This is a more readable version of your code.
Code:
//Function to transfer output from array to output port
void showout()
{
   if(n == 1)
   {
      for(j=0;j<8;j++)
      {
         output_b(outta1[j]);
         delay_ms(timema[j]);
      }
   }
   if(n == 2)
   {
      for(j=0;j<8;j++)
      {
         output_b(outta2[j]);
         delay_ms(timema[j]);
      }
   }
   if(n == 3)
   {
      for(j=0;j<8;j++)
      {
         output_b(outta3[j]);
         delay_ms(timema[j]);
      }
   }
   if(n == 4)
   {
      for(j=0;j<8;j++)
      {
         output_b(outta4[j]);
         delay_ms(timema[j]);
      }
   }
   if(n == 5)
   {
      for(j=0;j<8;j++)
      {
         output_b(outta5[j]);
         delay_ms(timema[j]);
      }
   }
   if(n == 6)
   {
      for(j=0;j<8;j++)
      {
         output_b(outta6[j]);
         delay_ms(timema[j]);
      }
   }
}
[b]
this is output function how to call it in the  programme

You call it by having this line somewhere else in your code.
Code:
showout();


Mike

What we asked for was a SHORT complete compilable code which shown the problem you wer having.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Feb 17, 2014 1:33 am     Reply with quote

ad as I've already pointed out the whole code for this function can reduce to just eight lines:
Code:

void showout()
{
   for(j=0;j<8;j++)
   {
       output_b(outta[i-1][j]);
       delay_ms(timema[j]);
   }
}

//If the declaration of outta is changed to a multidimensional array:
int8 outta[6][8]= {
   {0b00000000,0b00000100,0b0000 0110,0b00000111,0b00000111,0b0 0000110,0b00000100,
0b00000000},
   {0b00000000,0b00000010,0b0000 0110,0b00000111,0b00000111,0b0 0000110,0b00000010,
0b00000000}, //four more lines not shown from here

};

_Think_....
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