27-07-2012, 02:43 PM | #2 | |
Đệ tử 7 túi
Tham gia ngày: May 2005
Bài gửi: 258
: |
Trích:
Code:
#include <16F877A.h> #include <def_877a.h> #device adc=10 #FUSES NOWDT, XT, PUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, WRT_50% #use delay(clock=4000000) #use fast_io(a) #use fast_io(b) #include <lcd_nokia3310.c> int8 model; float adc; #int_RB void RB_isr() { if( !input(PIN_B4) ) { output_c(0xff); model =model+1; if(model==3) model =1; nokia_clear_screen(); switch (model) { case 1: { adc = read_adc(); nokia_gotoxy(0,0); printf(nokia_printchar,"ADC!"); nokia_gotoxy(17,2); printf(nokia_printchar,"%4.3f",adc); delay_us(10); } break; case 2: { nokia_gotoxy(17,2); printf(nokia_printchar,"Interrupts"); delay_us(10); } break; } clear_interrupt(int_rb); } } void main() { set_tris_a(0xff); // all input set_tris_b(0xff); port_b_pullups(true); // treo tro port b set_tris_c(0x00); set_tris_d(0x00); // all output ext_int_edge(H_to_L); setup_adc_ports(AN0); setup_adc(ADC_CLOCK_DIV_2); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_RB); enable_interrupts(GLOBAL); // TODO: USER CODE!! model =1; nokia_init(); nokia_gotoxy(0,0); printf(nokia_printchar,"ADC!"); while(true) { switch (model) { case 1: { adc = read_adc(); nokia_gotoxy(17,2); printf(nokia_printchar,"%4.3f",adc); delay_ms(100);//thoi gian lay mau adc } break; } } }
__________________
viết chương trình cho vdk chạy ổn định là cả một vấn đề. |
|
|
|