#include <xc.h> #define _XTAL_FREQ 4000000 // 4MHz crystal // Configuration bits #pragma config FOSC = HS // High-speed oscillator #pragma config WDTE = OFF // Watchdog timer off #pragma config PWRTE = OFF // Power-up timer off #pragma config BOREN = OFF // Brown-out reset off #pragma config LVP = OFF // Low-voltage programming off #pragma config CPD = OFF // Data EEPROM code protection off #pragma config WRT = OFF // Flash program memory write off #pragma config CP = OFF // Flash program memory code protection off void UART_Init() { TXSTA = 0x24; // Enable TX, high speed RCSTA = 0x90; // Enable serial port, continuous receive SPBRG = 25; // Baud rate 9600 for 4MHz crystal } void UART_Write(char data) { while(!TRMT); // Wait for transmit shift register to be empty TXREG = data; // Write data to TX register } void UART_Write_Text(char *text) { while(*text) { UART_Write(*text++); } } void main() { TRISB = 0x01; // RB0 input (button), RB1 output (LED) PORTB = 0x00; // Clear PORTB UART_Init(); // Initialize UART while(1) { if(RB0 == 1) { // Button pressed RB1 = 1; // Turn on LED (simulate shutter) UART_Write_Text("PHOTO_CLICKED\n"); // Send signal __delay_ms(500); // Simulate shutter duration RB1 = 0; // Turn off LED __delay_ms(500); // Debounce } } }
Standard input is empty
#include <xc.h> #define _XTAL_FREQ 4000000 // 4MHz crystal // Configuration bits #pragma config FOSC = HS // High-speed oscillator #pragma config WDTE = OFF // Watchdog timer off #pragma config PWRTE = OFF // Power-up timer off #pragma config BOREN = OFF // Brown-out reset off #pragma config LVP = OFF // Low-voltage programming off #pragma config CPD = OFF // Data EEPROM code protection off #pragma config WRT = OFF // Flash program memory write off #pragma config CP = OFF // Flash program memory code protection off void UART_Init() { TXSTA = 0x24; // Enable TX, high speed RCSTA = 0x90; // Enable serial port, continuous receive SPBRG = 25; // Baud rate 9600 for 4MHz crystal } void UART_Write(char data) { while(!TRMT); // Wait for transmit shift register to be empty TXREG = data; // Write data to TX register } void UART_Write_Text(char *text) { while(*text) { UART_Write(*text++); } } void main() { TRISB = 0x01; // RB0 input (button), RB1 output (LED) PORTB = 0x00; // Clear PORTB UART_Init(); // Initialize UART while(1) { if(RB0 == 1) { // Button pressed RB1 = 1; // Turn on LED (simulate shutter) UART_Write_Text("PHOTO_CLICKED\n"); // Send signal __delay_ms(500); // Simulate shutter duration RB1 = 0; // Turn off LED __delay_ms(500); // Debounce } } }