Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

PIC 16f877A trigger idea

Status
Not open for further replies.

cheekang

Newbie level 6
Joined
Jan 28, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,374
hi all need some idea.

bellow are my coding that get from cyrton.

Code:
//=============================================================================================
//
//	Author				:Cytron Technologies		
//	Project				:DIY Project
//	Project description	:PR6-Bluetooth Remote Control
//  Date				:21 May 2009
//
//=============================================================================================


//=============================================================================================
// Include file
//=============================================================================================
#include <pic.h>


//=============================================================================================
// Configuration
//=============================================================================================
__CONFIG(0x3F32);


//=============================================================================================
//Define
//=============================================================================================
#define seg PORTD				// define 7 segment as PORTD 


//==============================================================================================
// Function Prototype
// User can write all the necessary function here
//==============================================================================================

	
unsigned char a;

void init(void)					// subroutine to initialize  			
{	
	SPBRG=0x0A;					// set baud rate as 115200 baud
	BRGH=1;	
	TXEN=1;
	CREN=1;
	SPEN=1;
	TRISD = 0b00000000;			
	seg   = 0b00000000;			
}

void display(unsigned char c)		// subrountine to display the text on the screen	
{
	while (TXIF == 0);
	TXREG = c;	
}

unsigned char receive(void)			// subrountine to receive text from PC
{
	while (RCIF == 0);
	a = RCREG;
	return a;
}


//================================================================================================
//	Main Function
//	This is the main function where program start to execute 
//================================================================================================
void main(void)
{
	init();


    while(1)				// Wait for 'ok' to be entered by user
	{
		a = receive();								
		if (a == 'o') 						
			{
				a = receive();
				if (a == 'k') break;
			}
	}


		display('C');			// Text will display on Hyperterminal after 'ok' is entered
		display('y');
		display('t');
		display('r');
		display('o');
		display('n');
		display(0x0a);			//Go to new line	
		display(0x0d);			
		display('P');
		display('r');
		display('e');
		display('s');
		display('s');
		display(0x20);			// Space
		display('a');
		display('n');
		display('y');
		display(0x20);			// Space
		display('n');
		display('u');
		display('m');		
		display('b');
		display('e');
		display('r');

		seg = 1;	

		// wait for number and display it on 7 segment
        // The number display on 7 segment is depends on what number entered in Hyperterminal.
		while(1)	
		{
			a = receive(); 
			if (a=='1'||a=='2'||a=='3'||a=='4'||a=='5'||a=='6'||a=='7'||a=='8'||a=='9'||a=='0')
			{
				seg = a-0x30;
			}
		}

}
#above coding is from cytron
HTML:
http://www.cytron.com.my/usr_attachment/Source%20Code%20PR6.zip
, and the concept of project is
HTML:
http://www.cytron.com.my/usr_attachment/PR6A_DD.pdf

1.PNG2.PNG

the code function is like: when the user key in "ok" in hyperterminal it will auto get reply and display "cytron press any number" in hyperterminal.
I wish to change the concept flow.
i wish to key in the "ok" by using a push button that connect to PIC16F877A
(the user key in "ok" in hyperterminal is replace by pressing the push button that connect to PIC)
once the push button is trigger, it will auto send "ok" to the Bluetooth module, and the hyperterminal will auto get the reply "cytron press any number".
i wish to replace this code key in by using push button.
Code:
while(1)				// Wait for 'ok' to be entered by user
	{
		a = receive();								
		if (a == 'o') 						
			{
				a = receive();
				if (a == 'k') break;
			}
	}

kindly advice, above function i need to use interrupt or any alternative way?
my push button will connect to pin 33 (PB0) in pic16f877a.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top