fork download
  1. #include <xc.h>
  2. #define _XTAL_FREQ 4000000 // 4MHz crystal
  3.  
  4. // Configuration bits
  5. #pragma config FOSC = HS // High-speed oscillator
  6. #pragma config WDTE = OFF // Watchdog timer off
  7. #pragma config PWRTE = OFF // Power-up timer off
  8. #pragma config BOREN = OFF // Brown-out reset off
  9. #pragma config LVP = OFF // Low-voltage programming off
  10. #pragma config CPD = OFF // Data EEPROM code protection off
  11. #pragma config WRT = OFF // Flash program memory write off
  12. #pragma config CP = OFF // Flash program memory code protection off
  13.  
  14. void UART_Init() {
  15. TXSTA = 0x24; // Enable TX, high speed
  16. RCSTA = 0x90; // Enable serial port, continuous receive
  17. SPBRG = 25; // Baud rate 9600 for 4MHz crystal
  18. }
  19.  
  20. void UART_Write(char data) {
  21. while(!TRMT); // Wait for transmit shift register to be empty
  22. TXREG = data; // Write data to TX register
  23. }
  24.  
  25. void UART_Write_Text(char *text) {
  26. while(*text) {
  27. UART_Write(*text++);
  28. }
  29. }
  30.  
  31. void main() {
  32. TRISB = 0x01; // RB0 input (button), RB1 output (LED)
  33. PORTB = 0x00; // Clear PORTB
  34. UART_Init(); // Initialize UART
  35.  
  36. while(1) {
  37. if(RB0 == 1) { // Button pressed
  38. RB1 = 1; // Turn on LED (simulate shutter)
  39. UART_Write_Text("PHOTO_CLICKED\n"); // Send signal
  40. __delay_ms(500); // Simulate shutter duration
  41. RB1 = 0; // Turn off LED
  42. __delay_ms(500); // Debounce
  43. }
  44. }
  45. }
Success #stdin #stdout 0.04s 25620KB
stdin
Standard input is empty
stdout
#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
        }
    }
}