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.
How should i add interrupt in this...
sorry to say i am still confuse with that tmr2 overflow i am not able to understand why at delay only it is going to ISr routine??
it will be easier to learn isr with a very basic program...
 
The reason the interrupt "interrupts" the program flow during the delay, is because the delay is the biggest part of the program flow.... The interrupt is fired when TMR2 overflows... TMR2 is running in the background and every machine cycle ( or pe-scaled cycles) the timer is increased..... when it gets to the value in PR2 it interrupts the main program, wherever it may be...
 
Hi,

my new code....working fine with row scanning and left right up down....
need your help while scrolling left the default storage may be coming on display pls tell how to remove it!!
and while using the bit shift>> and << the bit goes out from it i mean how to make it like circular array......

Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
#define DAD PORTB
#define RST RC6
#define CLK RC3
#define DATA RC4
extern const char Font2[];unsigned char leds[31];unsigned char pow[] = {128,64,32,16,8,4,2,1};
display(char *str);int data( int p);int t;char b,e;void clear(void);
main ()
	{
	TRISC=0B00000000;
	TRISB=0B00000000;
	while(1)
		{
		display("AKON>");
		for(char t=0;t<10;t++)
			{
			for(char y=0;y<10;y++)
				{
				RST=0;
				RST=1;
				char u=-1;
				b=0b00000001;
				for(int r=0;r<8;r++)
					{
					DAD=pow[r];
					__delay_ms(2);
					RST=0;
					RST=1;
					u++;
					for(int a=0;a<32;a++)
						{
						DAD=0;
						RST=1;
						char t,n;
						n=leds[a];
						n>>=u;
						t=(n & b);
						if(t==0){DATA=0;}
						if(t==1){DATA=1;}
						CLK=1;
						__delay_us(10);
						CLK=0;
						}
					}
				}
			for(char t=0;t<5;t++)
				{
				leds[t]>>=1;
				__delay_ms(1);
				}
			}
 		clear();
		display("AKON>");
		for(char t=0;t<10;t++)
			{
			for(char y=0;y<10;y++)
				{
				RST=0;
				RST=1;
				char u=-1;
				b=0b00000001;
				for(int r=0;r<8;r++)
					{
					DAD=pow[r];
					__delay_ms(2);
					RST=0;
					RST=1;
					u++;
					for(int a=0;a<32;a++)
						{
						DAD=0;
						RST=1;
						char t,n;
						n=leds[a];
						n>>=u;
						t=(n & b);
						if(t==0){DATA=0;}
						if(t==1){DATA=1;}
						CLK=1;
						__delay_us(10);
						CLK=0;
						}
					}
				}
			for(char t=5;t<11;t++)
				{
				leds[t]>>=1;
				__delay_ms(1);
				}
			}
		clear();
		display("AKON>");

		for(char t=0;t<10;t++)
			{
			for(char y=0;y<10;y++)
				{
				RST=0;
				RST=1;
				char u=-1;
				b=0b00000001;
				for(int r=0;r<8;r++)
					{
					DAD=pow[r];
					__delay_ms(2);
					RST=0;
					RST=1;
					u++;
					for(int a=0;a<32;a++)
						{
						DAD=0;
						RST=1;
						char t,n;
						n=leds[a];
						n>>=u;
						t=(n & b);
						if(t==0){DATA=0;}
						if(t==1){DATA=1;}
						CLK=1;
						__delay_us(10);
						CLK=0;
						}
					}
				}
			for(char t=11;t<17;t++)
				{
				leds[t]>>=1;
				__delay_ms(1);
				}
			}
		clear();
		display("AKON>");
		for(char t=0;t<10;t++)
			{
			for(char y=0;y<10;y++)
				{
				RST=0;
				RST=1;
				char u=-1;
				b=0b00000001;
				for(int r=0;r<8;r++)
					{
					DAD=pow[r];
					__delay_ms(2);
					RST=0;
					RST=1;
					u++;
					for(int a=0;a<32;a++)
						{
						DAD=0;
						RST=1;
						char t,n;
						n=leds[a];
						n>>=u;
						t=(n & b);
						if(t==0){DATA=0;}
						if(t==1){DATA=1;}
						CLK=1;
						__delay_us(10);
						CLK=0;
						}
					}
				}
			for(char t=18;t<23;t++)
				{
				leds[t]>>=1;
				__delay_ms(1);
				}
			}
		clear();
		display("AKON>");
		for(char t=0;t<10;t++)
			{
			for(char y=0;y<10;y++)
				{
				RST=0;
				RST=1;
				char u=-1;
				b=0b00000001;
				for(int r=0;r<8;r++)
					{
					DAD=pow[r];
					__delay_ms(2);
					RST=0;
					RST=1;
					u++;
					for(int a=0;a<32;a++)
						{
						DAD=0;
						RST=1;
						char t,n;
						n=leds[a];
						n>>=u;
						t=(n & b);
						if(t==0){DATA=0;}
						if(t==1){DATA=1;}
						CLK=1;
						__delay_us(10);
						CLK=0;
						}
					}
				}
			for(char t=0;t<32;t++)
				{
				leds[t]>>=1;
				}
			}
		clear();
		display("AKON>");
		for(char t=0;t<10;t++)
			{
			for(char y=0;y<10;y++)
				{
				RST=0;
				RST=1;
				char u=-1;
				b=0b00000001;
				for(int r=0;r<8;r++)
					{
					DAD=pow[r];
					__delay_ms(2);
					RST=0;
					RST=1;
					u++;
					for(int a=0;a<32;a++)
						{
						DAD=0;
						RST=1;
						char t,n;
						n=leds[a];
						n>>=u;
						t=(n & b);
						if(t==0){DATA=0;}
						if(t==1){DATA=1;}
						CLK=1;
						__delay_us(1);
						CLK=0;
						}
					}
				}
			for(char t=0;t<32;t++)
				{
				leds[t]<<=1;
				}
			}

		display("AKON>");
		for(char e=0;e<32;e++)
			{
			for(char y=0;y<20;y++)
				{
				RST=0;
				RST=1;
				char u=-1;
				b=0b00000001;
				for(int r=0;r<8;r++)
					{
					DAD=pow[r];
					__delay_ms(2);
					RST=0;
					RST=1;
					u++;
					for(int a=0;a<32;a++)
						{
						DAD=0;
						RST=1;
						char t,n;
						n=leds[a];
						n>>=u;
						t=(n & b);
						if(t==0){DATA=0;}
						if(t==1){DATA=1;}
						CLK=1;
						__delay_us(1);
						CLK=0;
						}
					}
				}
			for(char t=0;t<32;t++)
				{
				leds[t]=leds[t+1];
				}
			}
		clear();
		}
	}


display(char *str)   
	{

	int addr;                                                      
	int z;
	while(*str!=0){
		addr = ((int)*str++ - 0x20); 
		addr *= 5;
		int y=0;
		for(z=0;z<5;z++){
			leds[z] = Font2[addr+y];
			y++;
			}
		addr = ((int)*str++ - 0x20); 
		addr *= 5;
		int y=0;
		for(z=6;z<11;z++){
			leds[z] = Font2[addr+y];
			y++;
			}
		addr = ((int)*str++ - 0x20); 
		addr *= 5;
		int y=0;
		for(z=12;z<17;z++){
			leds[z] = Font2[addr+y];
			y++;
			}
		addr = ((int)*str++ - 0x20); 
		addr *= 5;
		int y=0;
		for(z=18;z<23;z++){
			leds[z] = Font2[addr+y];
			y++;
			}
		addr = ((int)*str++ - 0x20); 
		addr *= 5;
		int y=0;
		for(z=24;z<29;z++){
			leds[z] = Font2[addr+y];
			y++;
			}
		}
	}



void clear(void){
	for(char y=0;y<31;y++){
	leds[y]=0x00;
	}
}
 
Last edited by a moderator:
Hi,
please give suggestion how to build buffer for string of character more than buffer size.....
 
In column scanning i found one problem when column size increase the scroll flicker/vibrate due to scanning big size....but in my new code for rows scanning there is no problem......it moves soo smoothly and with effect.....i just need help with led buffer filling.
 
No disrespect intended!!! Your code is...... Well... VERY difficult to follow... I re-read it several times to find out your logic..

You need to build an engine..... The purpose of the engine is to do the mundane tasks.. All those nested "if" statements are extremely inefficient...

You need to drive the LED update in a function which is called systematically..... Otherwise you will have real difficulty changing things.. Like for example, the string for display
 
All those nested "if" statements are extremely inefficient

just neglect that if statement i was just creating reverse style at display for testing just DATA=t;

As i said i am doing Row scanning so, i was using b=00000001; 'ANd' with the buffer rows with shifting after completing all column...
after that the shifting of column or Rows is done for scrolling up/down/left....
then clear is called b'cz the buffer are filled with default value and then again display is called to fill it...
 
In C you should be able to create an unsigned long ( well 8 of them really ) this will be your group of LED buffers... Then "buffer <<=1;" will scroll the data right.

There is a useful feature in C, which is really underused.. Its a union. This is a data structure in which all the elements are contained within the same data space.

union.png


This way when you shift the long, the bytes ( which become your buffers ) are automatically aligned.
 
Can you explain me bit more what are you trying to say for??
as led buffer is made of rows and colun so what will be the use of making long, then char not claer to me..?????
and please help me with assm instruction the ROL and ROL how to do this in C.
 
Right!!! You are not helping me..... I gave you everything you need to make a 8x24 LED scrolling machine using column scanning...

You have decided that the original plan of row scanning is a better option.... 32 bits is an unsigned long .. You need to scroll the long left or right... AND you need to feed the data 1 byte at a time..

This is why its easier to do this off screen... (and a lot easier to do columns) Scrolling the buffer is simple... "buffer<<=1;" scrolls the buffer 1 but you have 4 buffers in a line so using the full 32 bits will make it easier for you...
 
Hi,

i was testing unsigned long in place of unsigned char for leds buffer it is showing error why??
invalid conversion between pointer, why??
 
This is advanced stuff.... I really can't write another routine... You CAN'T use an unsigned long You would need to re-write the whole thing.... The suggestion of using a union is not going to help you until you can grasp the concept...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top