Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

error interrupt driven usart please help

Status
Not open for further replies.

izwirlee_35

Member level 1
Joined
Sep 20, 2010
Messages
33
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,462
Hİ for all ! I have not been around just because of I'm at army and away from programmes I want to use usart with interrupts but its not working can you help me ?

There are two codes below one of buttons with pic other one is leds with pic




buttons with pic



Code:
#include <pic.h>
#include "always.h"
#include "delay.h"
#include "usart.h"
#include "clk_freq.h"

unsigned char i;
const unsigned char * gtck_tx;
unsigned char buff_tx[20],buff_tx_adr;
unsigned char buff_rx[20],buff_rx_adr=0;


void port_kur()
	{
	CMCON=7;OPTION=0x00;
	PORTB=0x00;
	TRISB=0b01111010;
	seri_kur(9600);
	seri_temizle();DelayMs(5);
	}

//********************************************************
	void gndr_tx(const unsigned char * gtck_tx)
	{
	i=0;buff_tx_adr=0;
	do
	{
	buff_tx[i]=*gtck_tx;
	i++;
	}while(*gtck_tx++);
	TXIE=1;
	}

	void calis()
	{
	
	
			if(!RB3){while(!RB3);gndr_tx("a");return;}
			else if(!RB4){while(!RB4);gndr_tx("b");return;}
			else if(!RB5){while(!RB5);gndr_tx("c");return;}
			else if(!RB6){while(!RB6);gndr_tx("d");return;}
			else return;
	}

	
	void main()
{
	port_kur();

	GIE=1;
	PEIE=1;

	do
	{
	calis();
	
	}
	while(1);

} 

//*********************************************************
//*********************************************************


static void interrupt Kesme(void)
{

		if(TXIF){
			
				if(buff_tx[buff_tx_adr]!='\0')
				{
				
				TXREG=buff_tx[buff_tx_adr++];
			
				}
				else {TXIE=0;}
			TXIF=0;
				}

		if(RCIF){
			
			buff_rx[buff_rx_adr]=RCREG;
			buff_rx_adr++;
			
			RCIF=0;
			}
}


leds with pic

Code:
#include <pic.h>
#include "always.h"
#include "delay.h"
#include "usart.h"
#include "clk_freq.h"

unsigned char i,j,k;
const unsigned char * gtck_tx;
unsigned char buff_tx[20],buff_tx_adr;
unsigned char buff_rx[20],buff_rx_adr=0;
unsigned char m,z,gelen_pkt_tmm=0;
signed char kars_sonuc;
const unsigned char * gln_kars;

void port_kur()
{
CMCON=7;
PORTA=0x00;
TRISA=0b00000000;
PORTB=0x00;
TRISB=0b00000010;
seri_temizle();DelayMs(5);
seri_kur(9600);
}

//*****************************************************
	void gndr_tx(const unsigned char * gtck_tx)
	{
	j=0;buff_tx_adr=0;
	do
	{
	buff_tx[j]=*gtck_tx;
	j++;
	}while(*gtck_tx++);
	TXIE=1;
	}


	unsigned char kars(const unsigned char *gln_kars)
	{	m=0;kars_sonuc=0;z=0;
	do
	{
	CLRWDT();
	while(!gelen_pkt_tmm);
	kars_sonuc=buff_rx[m]-*gln_kars;
	m++;gln_kars++;  //kars_1++ ile  pointerini artırmak yerine *kars_1++ ile pointerin içeriğini artırıyorsunuz.
	}
	while(*gln_kars);
	if(kars_sonuc<0){z=0;}
	else if(kars_sonuc>0){z=0;}
	else if (kars_sonuc==0){z=1;}
return z;
	}

//**************************************************************

void oku(){
		
			if(RCIF)
			{
			if(kars("a")){RB3=!RB3;if(RB3)gndr_tx("led1 is active\r\n");if(!RB3)gndr_tx("led1 is passive\r\n");}
			else if(kars("b")){RB4=!RB4;if(RB4)gndr_tx("led2 is active\r\n");if(!RB4)gndr_tx("led2 is passive\r\n");}
			else if(kars("c")){RB5=!RB5;if(RB5)gndr_tx("led3 is active\r\n");if(!RB5)gndr_tx("led3 is passive\r\n");}
			else if(kars("d")){RB6=!RB6;if(RB6)gndr_tx("led4 is active\r\n");if(!RB6)gndr_tx("led4 is passive\r\n");}
			else return; 
			}
			else return;
		}			

void main()
{

port_kur();
GIE=1;
PEIE=1;


TMR2IF=0;
TMR2IE=0;
T1CON=0b00110001;
T2CON=0b00000111;

PR2=6;	//  230 = 3,68 



do
{
oku();
}
while(1);
} 


static void interrupt Kesme(void)
{

		if(TXIF){
			
				if(buff_tx[buff_tx_adr]!='\0')
				{
				
				TXREG=buff_tx[buff_tx_adr++];
			
				}
				else {TXIE=0;}
			TXIF=0;
				}
		if(RCIF){
			
			buff_rx[k++]=RCREG;
			if(k==5){k=0;gelen_pkt_tmm=1;}
			
			RCIF=0;    
			}
		
		if(TMR2IF)
		{
		RB7=!RB7;
		buff_rx_adr=0;
		PR2=6;
		TMR2IF=0;
		TMR2IE=0;
		}
}


File Hosting - Web Hosting - Dedicated Server
 

izwirlee_35

Member level 1
Joined
Sep 20, 2010
Messages
33
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,462
so many thanks for your repliessssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
 

izwirlee_35

Member level 1
Joined
Sep 20, 2010
Messages
33
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,462
so many thanks for your repliessssssssssssssssssssssssssssssssssssssssssss ssssssssssssssssssssssssss
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top