Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <main.h>
- #include <flex_lcd.c>
- // Ad hoc programming, only for testing purpose (demo).
- // Needs to be revised before using.
- #define button PIN_B0
- // ┆ Vcc
- // ┆ │
- // ┆ ┌─┴─┐
- // ┆ │ │ RESISTOR (R)
- // ┆ │ │
- // ┆ └─┬─┘ R = t / ( C * log ( Vcc / Vcc - Vr ) )
- // ────────┆──┐ │ t -> Time / Vr -> Voltage reference
- // PIN A0 ┆ ├──── █ Vcc -> Voltage applied
- // ────────┆──┘ │
- // ┆ ───┴─── CAPACITOR (C)
- // ┆ ───┬───
- // ┆ │ * R > 200 Ω
- // ┆ GND * C <= 0.1 µF
- int overflow=0;
- int32 clk_val=0;
- #INT_COMP
- void comp_int(){
- setup_timer_1( T1_DISABLED );
- disable_interrupts(INT_COMP);
- disable_interrupts(INT_TIMER1);
- clk_val = get_timer1() + 65536 * overflow;
- set_timer1(0);
- lcd_gotoxy(9,1);
- printf( lcd_putc, "%8lu\n%03u", clk_val, overflow );
- overflow=0;
- }
- #INT_TIMER1
- void tmr_over(){
- overflow++;
- if(overflow == 255){
- reset_cpu();
- }
- }
- void main()
- {
- lcd_init();
- output_low(PIN_A6);
- port_b_pullups(true);
- printf(lcd_putc, "Hello World!\nPress Button!");
- while(!input(button));
- while(input(button));
- lcd_init();
- enable_interrupts(GLOBAL);
- setup_vref(VREF_LOW | 12);
- set_timer1(0);
- overflow=0;
- clk_val=0;
- output_low(PIN_A1);
- while(true){
- output_low(PIN_A0);
- while(input(button));
- delay_ms(5);
- setup_comparator( A0_VR_A1_VR );
- enable_interrupts(INT_COMP);
- enable_interrupts(INT_TIMER1);
- setup_timer_1( T1_INTERNAL | T1_DIV_BY_1 );
- output_high(PIN_A6);
- while(! interrupt_active(INT_COMP) );
- clear_interrupt(INT_COMP);
- output_low(PIN_A6);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement