PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Analog - Bộ nhớ - Bảo mật - Cảm biến nhiệt độ

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Tìm Kiếm Bài Trong Ngày Ðánh Dấu Ðã Ðọc Vi điều khiển

Analog - Bộ nhớ - Bảo mật - Cảm biến nhiệt độ Thảo luận việc sử dụng và thay thế các sản phẩm Analog, Memory, KEELOG và cảm biến nhiệt độ của Microchip cho các thiết kế

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 09-12-2011, 09:45 PM   #3
tdm
Đệ tử 7 túi
 
Tham gia ngày: May 2005
Bài gửi: 258
:
Trích:
Nguyên văn bởi phamvanduan View Post
em viết thử ADC ma sao chay không dúng.dù thay đổi điện áp vào chân AN0 như thế nào thi adc vẫn đọc duy nhất 1 giá trị.cụ thể trong code là chỉ có led0 sáng.
thanks mọi người

#include <18F4431.h>
#device adc=10

#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV27 //Brownout reset at 2.7V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOWINEN //WDT Timer Window Disabled
#FUSES T1LOWPOWER //Timer1 low power operation when in sleep
#FUSES HPOL_HIGH //High-Side Transistors Polarity is Active-High (PWM 1,3,5 and 7)
//PWM module high side output pins have active high output polarity
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPOL_HIGH //Low-Side Transistors Polarity is Active-High (PWM 0,2,4 and 6)
//PWM module low side output pins have active high output polar
#FUSES PWMPIN //PWM outputs disabled upon Reset
#FUSES MCLR //Master Clear pin enabled
#FUSES FLTAC1 //FLTA input is multiplexed with RC1
#FUSES SSP_RC //SCK/SCL=RC5, SDA/SDI=RC4, SDO=RC7
#FUSES PWM4B5 //PWM4 output is multiplexed on RB5
#FUSES EXCLKC3 //TMR0/T5CKI external clock input is muliplexed with RC3

#use delay(clock=20000000)
#byte PORTA = 0xF80
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#bit led0 = PORTD.0
#bit led1 = PORTD.1
#bit led2 = PORTD.2
#bit led3 = PORTD.3
#bit led4 = PORTD.4

void main()
{
int done;
int16 adc;
set_tris_A(0xff);
set_tris_D(0x00);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
while(true)
{
set_adc_channel(sAN0);
delay_ms(10);
adc = read_adc();
delay_us(100);
if(adc<400) led0=1;
else led1=1;

}

}
vẫn chạy bình thường .
nếu bạn mô phỏng trên proteus thì phải nối nguồn cho chân AVDD,AVSS
__________________
viết chương trình cho vdk chạy ổn định là cả một vấn đề.
tdm vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 

Ðiều Chỉnh
Xếp Bài

Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 11:02 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam