Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to use Interrupt in PIC16F877A in C..??

Status
Not open for further replies.
If you want a single statement ie..
Code:
if ( x== 0 )  PORTB=2;
You can also write..
Code:
if ( x== 0 ) 
   PORTB=2;
You can also write..
Code:
if ( x== 0 ) 
   {
   PORTB=2;
   }

BUT!!! f there are more than one statements it MUST have the curly brackets
Code:
if ( x== 0 ) 
   {
   PORTB = 2;
   PORTC = 1;
   }
So Naturally I use A) the first

Code:
if ( x== 0 ) PORTB=2;

Or B) the last....

When you debug the first bit of code... You need to separate the two lines so you can check the operation...
 
I have doubt with this also..........
{} // REMOVED the WDT function!!!!

if(!T0IF) // Was this a timer overflow?
bad_intr = 1; // NO! Shock horror!


PORTB ^= 1;
explain this also....not clear to me
 
I have doubt with this also..........
{} // REMOVED the WDT function!!!!

Okay... You are spending too much time on trivial stuff

The original code was
Code:
for( ; ; )
   CLRWDT();

You didn't understand... So I removed it and placed a __CONFIG(); at the top..
Code:
 for( ; ; )
   {}
You can either HAVE the empty curly brackets or not.... It's up to you...
if(!T0IF) // Was this a timer overflow?
bad_intr = 1; // NO! Shock horror!

If NOT Timer0InterruptFlag...
bad interrupt is then flagged..
PORTB ^= 1;
explain this also....not clear to me

Port b is XORED with 1 C shortcut.. Same as PORTB = PORTB XOR 1 in basic... (Toggle)
 
OK, I am working scrolling LED display for 8x8 LED matrix just for now so, i have used 4017 it was working fine with big code without any keypad to input the data ...
but after searching i found 74164 is used for serial to parallel converter for cascading large column so, i have problem to convert the data example 0x5f to serial feeding to 74164 i was using data array to solve this problem..i have to convert hex to binary vice versa.

Code:
int a[8]= {0,1,0,1,1,1,1,1};
for(int i=0; i<8;i++){
RST=0;
RST=1;
CLK=0;
CLK=1;
data=a[i];
}


please tell how to do this in fast and efficient way!!
 
I have seen this on AAC... Can you post me a small schematic so I can see what you're doing... I'd like to have it on ISIS, so I can see whats occurring!!! Then I'll be able to test the code you post.

I'll try and grab the code you posted on AAC as well.
 
Here is schematic 4017 to 74164 the data a b are connected to gather to PORTD7 and clk and reset to PORTD6 PORTD5...like this.
 

Attachments

  • 12.jpg
    12.jpg
    1 MB · Views: 204
OK... First off... Why do we need the external IC'c? The schematic shows a pic16f84a, If you use a 877a you can use port D for rows and port C for columns!!

If you intended to expand the column drivers to incorporate MANY 8x8 matrices I'll use the 4017 and 74164 to drive a single matrix!!

If you are driving "several" matrices, you may not be able to keep up the duty cycle needed for a ficker free display...


Come to think of it... Why do you need the decade counter???

In my "Nigel's tutorials in C" https://www.electro-tech-online.com/threads/directorial-antenna.467/ Tutorial 13

In here you can find out how Nigel used TMR2 interrupt to run ASCII text on an 8x8 matrix.
 
Last edited:
I have seen many application notes which say, when you need to connect large number of Led shift register are used...to shift the same data and scroll like that.
one thing more i am having problem in initializing 2D array in MP lab showing error..

int abc[2][7]={{0x0,0x1,x0x2,0x2,0x5,0x8,} {0xf,0xa,x0x2,0x2,0x5,0x8,}};

please help me and provide a simple program containing 2D array.
 
You asked how to initialize a 2d array!!!! I showed you why yours didn't work....


I have solved that silly problem missing ,
I was initializing font through it but only few were saved because of memory space was near to full 89.9%
so, i watched program spaced and EEPROM was empty!! how to use it??
 
Its all in the tutorial.

seen your tut_6 all part but not clear how to use internal EEPROM of 877a and in user guide i found
Code:
 eeprom_write(0x10, 0x1f);
after this i build the project and view>EEPROM there is no values stored in it...,why?
 
My tutorial 6 is for EXTERNAL eeprom not the small part in the pic I use a 24lc256 I2C eeprom...

But if i want to use internal E2PROM then what command to use as i have seen user note of hi tech C but not working may be some fault......pls help with it..
The file i have attached(font) is to be saved as .H file then called by its row col.
 

Attachments

  • rk font.txt
    5.9 KB · Views: 214
here s the code i am using to text and scroll.
int a[row][7]={};
row=6 it work but when row>6 shows memory full on window of MP

Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_XT);
#define _XTAL_FREQ 4000000
#define DAD PORTB
#define RST RD7
#define CLK RD4
#define DATA RD5
#define D 1
int data(int a);

int v;
 main (){
TRISB=0B00000000;
TRISD=0B00000000;
int row;
int  b[6][7]=  {
{0x00, 0x0e, 0x01, 0x0d, 0x13, 0x13, 0x0d},//font
  {0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e,} ,  
   {0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x0e,} ,  
   {0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1f,} , 
   {0x0e, 0x11, 0x01, 0x06, 0x01, 0x11, 0x0e,}  ,
   {0x02, 0x06, 0x0a, 0x12, 0x1f, 0x02, 0x02,},

};
while(1){
DAD=0X00;
int a;
v=15;
for(row=0;row<6;row++)// for getting new character fromnext row
{ 
for(int o =0;o<15;o++)// for scrolling/moving the font by changing the bit store in 164
{
v--;
for (int k=0;k<50;k++)// just for holdong the character on led for mSec
{
a=b[row][0];
data(a);
DAD=0B10000000;
__delay_ms(D);

a=b[row][1];
data(a);
DAD=0B01000000;
__delay_ms(D);

a=b[row][2];
data(a);
DAD=0B00100000;
__delay_ms(D);

a=b[row][3];
data(a);
DAD=0B00010000;
__delay_ms(D);

a=b[row][4];
data(a);
DAD=0B00001000;
__delay_ms(D);

a=b[row][5];
data(a);
DAD=0B00000100;
__delay_ms(D);

a=b[row][6];
data(a);
DAD=0B00000010;
__delay_ms(D);





}
}
	}
	}
}


int data(int a)// serial to // converter for 164 
{
RST=0;
RST=1;

DAD=0X00;
  for (int k=0; k<v;k++) {  //send 8 bits
CLK = 0;  // serial clock low
    if ((a & 0x01)==1) DATA = 1;

    else DATA =0;

    CLK =1;

    a >>=1;
} }
 
The rows are only 6 in length..... There isn't a row 7 .. If you have the font in external file you need to reference it first.

Code:
extern const unsigned char Font1[32][17];   // delclare as external (in another file)
Near to the top BEFORE IT'S USED

You need to change this too..
const int Font1[32][7] = {
Declaring an int will waste memory..
const unsigned char Font1[32][7] = {
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top