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.
I have changes the sacnning from down left to rigt but the animation is not working it is hanging at starting only and scrolling is flickering/vibrating
 
Hi,
I want to write more lines but when i do this some overlapping occur due to which scrolling doesn't work well how to chose the value of x and y??

void displaystring(void) // this routine prints through the screen buffer
{ // moving one pixel at a time
signed char x=32,y=0; // I made these signed so I could print
for(y = 0;y < 300 ;y++) // to nowhere so I could produce the scrolling effect
{
clr(); // Clear the display buffer
strput("WELCOME TO SHIVALIK COLLEGE OF ENGINEERING, ELECTRICAL & ELECTRONICS ",x--,0); // adjust the scrolling string
Blit(); // pass to screen buffer
__delay_ms(80); // time to view
}
}
 
WELCOME TO SHIVALIK COLLEGE OF ENGINEERING, ELECTRICAL & ELECTRONICS

69 letters.... Eight pixels.... = 552 shifts.... This cannot be done with a char... You need to change to a signed int so the count will work...
 
so, x will be always 32???
and y will be 8x character

I use x=32 as this is just "off screen" the text then comes onto the screen at "x=31"

Y=0 as its the top left pixel...
 
Ok, if we have more character like 50 then we have to 400 value of x or y?? i have seen at large character it overlap!
 
Ok, if we have more character like 50 then we have to 400 value of x or y?? i have seen at large character it overlap!

Yes because the code I posted was for smaller strings.... If you change x and y to signed int's you can use strings up to 127 characters long...
 
Yes because the code I posted was for smaller strings.

then how to make it for bigger??

if i want to make this column scanning code to your row scanning then how to do convert/send buffer data??

Code:
#include<pic.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
#define DAD PORTB
#define RST RD7
#define CLK RC3
#define DATA RC4
 
 
 
char displayPointer=0;
extern const char  font[];
 
unsigned char buffer[32]; // buffer for screen
 
void interrupt ISR()		// This just swaps the buffer to the display
	{
	if(TMR2IF)				// make sure its the timer interrupt.
		{
		PORTB = 0;					// clear old data first
		if(displayPointer == 0 )  	// 1st frame..
			DATA = 1;				// Data = 1 on the first clock
		CLK = 1;
		__delay_us(10);				// Clock the shift registers
		CLK = 0;
     	DATA = 0;
		PORTB = buffer[displayPointer];	 // Move budffer line by line		
		if(++displayPointer==31) 		//  24 LED columns
			displayPointer = 0;			// back to first..
		}
	TMR2IF = 0;
	}
 
void display(const char* str)
	{
	int addr;
	char x, y;
	while(*str != 0)					// while there is still characters
		{
		addr = (int) *str++ - 0x20;		// get character
	//	DAD=addr;
 addr *=5;
//DAD=addr;
		for(y=0;y<5;y++)				// 5x8 font so 5 columns
			{
			buffer[31] = font[addr++];  // put it in buffer	
 
 	for(x=0;x<32;x++)
				{
				buffer[x] = buffer[x+1];	// shift all the columns <--
				//DAD=buffer[x];
__delay_ms(4);				// so you can see it
				}
			}
		buffer[31] = 0;						// This is the scpace between 
		for(x=0;x<32;x++)					// the characters.. Or they will be too close
			{
			buffer[x] = buffer[x+1];		//	shift the space in
			__delay_ms(5);
			}							// NOTE!!! your array is 28 not 24 like mine
		}	
	}
 
 
void main(void)
	{
	ADCON1 = 0x6;
	T2CON = 0x1e;	
	PR2 = 50;							// timer preload value
	TMR2IE = 1;							// enable timer 2 interrupt
	PEIE = 1;							// enable peripheral interrupt
	GIE = 1;							// enableglobal interrupt
	TRISB = 0;							// Port B as output...
	TRISC = 0;	
RST=1;						// Port C as ouput...
	while(1)
		{
		display("WELCOME     ");   // Here's the message
		}
	}	// End main
 
Do you not read my posts

If you change x and y to signed int's you can use strings up to 127 characters long...


You have two complete sets of code.... One I posted ages ago that gives column scanning... The other is row scanning...

You don't understand the code at all, do you??? When I see that you are trying to output to PORTB in the display routine, just shows that this concept is more advanced than you can handle... You need to get your head around the interrupt and how it drives the display.... Until then you are not going to get my code working on your hardware..
 
OK, if i will change it to signed long then we can display more right?
and x will be always 32, y will be dependable on number of character then if by some mistake less character are there but y is more than it then what will happen?
 
then here the value of y should be changed?? according to number of character?

Code:
for(y = 0;y < 300 ;y++)
 
To Ian Rogers

You have 10X the patience of JOB from the Bible. I really don't know how you do it.

Your mental health and sanity could be at risk.

Kindest regards,

A worried and concerned Doctor.
 
then here the value of y should be changed?? according to number of character?

Code:
for(y = 0;y < 300 ;y++)

I see your confusion.... In MY code

C:
void displaystring(void)				// this routine prints through the screen buffer
	{									// moving one pixel at a time
	signed char x=32,y=0;				// I made these signed so I could print 
	for(y = 0;y  < 96 ;y++)				// to nowhere so I could produce the scrolling effect
		{
		clr();							// Clear the display buffer
		strput("HELLO WORLD!!",x--,0);	// adjust the scrolling string
		Blit();							// pass to screen buffer
		__delay_ms(80);					// time to view
		}
	}

Y in this function is just a counter The function strput( char*, x, y); The y in the function is fixed at 0..

13 characters... so this will scroll 96 times...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top