samarters
|
|
« Reply #4 on: February 02, 2011, 04:51:52 PM » |
|
ลองใช้ของผมดูออกแน่นอน #include <18F4431.h> #device adc = 10 #fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT #use delay(clock=20000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define din pin_d2 #define cs pin_a5 #define clk pin_d3
void send_16bit(byte address,byte data) { byte i; #bit carry=0x03.0; carry=0; output_low(cs); for(i=0;i<8;i++) { if((address & 0b10000000)==0) output_low(din); else output_high(din); rotate_left(&address,1); output_high(clk); delay_us(50); output_low(clk); delay_us(50); }
for(i=0;i<8;i++) { if((data & 0b10000000)==0) output_low(din); else output_high(din);
rotate_left(&data,1); output_high(clk); delay_us(50); output_low(clk); delay_us(50); } output_high(cs); }
void init_7219() { send_16bit(0x09,0xff); //decode delay_us(10); send_16bit(0x0a,0x0f); //intensity delay_us(10); send_16bit(0x0b,0x07); //scan limit delay_us(10); send_16bit(0x0c,0x01); //shutdown delay_us(10); send_16bit(0x0f,0x00); //display delay_us(10); } void cal_num(int16 A,int16 V){ int tho,hun,dec,tho1,hun1,dec1; int b,c,d,e,f,g; tho = A/1000; b = A%1000; hun = b/100; c = b%100; dec = c/10; d = c%10; tho1 = V/1000; e = V%1000; hun1 = e/100; f = e%100; dec1 = f/10; g = f%10; send_16bit(5,tho1); send_16bit(6,hun1); send_16bit(7,dec1); send_16bit(8,g); send_16bit(1,tho); send_16bit(2,hun); send_16bit(3,dec); send_16bit(4,d); }
void main() { int16 value; MAXCNT = 9000; QEICON = 0x18; init_7219(); setup_adc_ports(sAN0); setup_adc(ADC_CLOCK_INTERNAL); while(true) { set_adc_channel(3); value = read_adc(); cal_num(POSCNT,Value); //แสดงค่า 7-segment 2 ค่า ในวงเล็บตัวแรกคือ 4 หลักบน ตัวหลัง คือ 4 หลักล่าง delay_ms(100); //printf("%lu\r\n",value);
} }
|