Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i connect button to the microcontroller board which is connected to pc via rs232 i want when this button release the pc will safe shuttdow through cmd command shutdown any help please

many thanks
Posted
Comments
Adham 1987 19-Sep-14 15:16pm    
THE CODE FOR MICROCONTROLLER:



#include <18F2620.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES H4 //High speed osc with HW enabled 4X PLL
#FUSES NOBROWNOUT //No brownout reset
#FUSES LVP //Low voltage prgming
#FUSES NOXINST //Extended mode disabled (Legacy mode)
#use delay(clock=40000000)
#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
int value = 1;
TRISA = 1; //Set PORTA as input
do
{
if(PORTA.RA0 != 1) //if button is not pressed

{

printf("%d", value); /* send formatted string via RS232 */

}
}while(1);

}


THIS CODE MUST SEND 1 TO THE PC WHAT I NEED IS A SIMPLE CODE WHICH RECEIVED THIS DATA (1) AND TURN PC OFF WHILE RELEASING THE BUTTON BUT FIRST OF ALL IS THE MICROCONTROLLER CODE IS CORRECT

MANY THANKS
Adham 1987 19-Sep-14 16:43pm    
AND PC LISTENING WITH CODE:

#include <bios.h>
#include <conio.h>
#define COM1 0
#define DATA_READY 0x100
#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)
int main(void)
{
int in, out, status;
bioscom(0, SETTINGS, COM1); /*initialize the port*/
cprintf("Data sent to you: ");
while (1)
{
status = bioscom(3, 0, COM1); /*wait until get a data*/
if (status & DATA_READY)
if ((out = bioscom(2, 0, COM1) & 0x7F) == 0) /*if no input data*/
system("C:\\WINDOWS\\System32\\shutdown -s");


}
return 0;
}


PLEASE ANY HELP ALL I NEED IS A CHECKUP

MANY THANKS

1 solution

Once the microcontroller detects the button press, it can send a 'shutdown' message to the your application running on the PC. The application, in turn, can shutdown Windows calling InitiateSystemShutdownEx[^] (please see the Remarks section)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900