วันพฤหัสบดีที่ 27 กุมภาพันธ์ พ.ศ. 2563


Home work

งานที่ 15

PIC16F676



คุณสมบัติ: 
หน่วยความจำข้อมูล EEPROM 128 ไบต์ 
ตัวต้านทานแบบดึงขึ้นที่ตั้งโปรแกรมได้ 
ช่องสัญญาณแอนะล็อกที่เลือกแยกได้ 
การสนับสนุนการเขียนโปรแกรม ICD2 หรือการสนับสนุนการดีบักด้วยอะแดปเตอร์ส่วนหัวเพิ่มเติม
- 8 oscillator sellections รวมถึงความแม่นยำ 4 MHz RC oscillator พร้อมการสอบเทียบที่ตั้งโปรแกรม
ได้และการเปิดเครื่องใหม่

ตัวอย่างการใช้งาน : การต่อ Voltmeter
ภาพวงจร



CODE
#include <16f676.h>
#FUSES NOWDT                   
#FUSES INTRC                 
#FUSES NOMCLR                 
#FUSES NOBROWNOUT            
#FUSES PUT
#device ADC=10
#use delay(INT=4Mhz)



#define aon    output_LOW(PIN_C0);
#define aof    output_HIGH (PIN_C0);

#define bon    output_LOW(PIN_C1);
#define bof    output_HIGH (PIN_C1);

#define con    output_LOW(PIN_C2);
#define cof    output_HIGH (PIN_C2);

#define don    output_LOW(PIN_C3);
#define dof    output_HIGH (PIN_C3);

#define eon    output_LOW(PIN_C4);
#define eof    output_HIGH (PIN_C4);

#define fon    output_LOW(PIN_C5);
#define fof    output_HIGH (PIN_C5);

#define gon    output_LOW(PIN_A2);
#define gof    output_HIGH (PIN_A2);






#define d1_of    output_LOW(PIN_A1);
#define d1_on    output_HIGH (PIN_A1);

#define d2_of    output_LOW(PIN_A0);
#define d2_on    output_HIGH (PIN_A0);

#define d3_of    output_LOW(PIN_A5);
#define d3_on    output_HIGH (PIN_A5);




int32  value=0,val2,ind=0,ind2=0,cnt5=0,d1;

void off();
int thu,ten,unit,digit;


void zero(){
 aon;
 bon;
 con;
 don;
 eon;
 fon;
 gof;
}
void one(){
 aof;
 bon;
 con;
 dof;
 eof;
 fof;
 gof;
}

void two(){
 aon;
 bon;
 cof;
 don;
 eon;
 fof;
 gon;
}

void three(){
 aon;
 bon;
 con;
 don;
 eof;
 fof;
 gon;
}
void four(){
 aof;
 bon;
 con;
 dof;
 eof;
 fon;
 gon;
}

void five(){
 aon;
 bof;
 con;
 don;
 eof;
 fon;
 gon;
}

void six(){
 aon;
 bof;
 con;
 don;
 eon;
 fon;
 gon;
}

void seven(){
 aon;
 bon;
 con;
 dof;
 eof;
 fof;
 gof;
}

void eight(){
 aon;
 bon;
 con;
 don;
 eon;
 fon;
 gon;
}

void nine(){
 aon;
 bon;
 con;
 don;
 eof;
 fon;
 gon;
}


void comp1(){

if(digit==0)zero();
if(digit==1)one();
if(digit==2)two();
if(digit==3)three();
if(digit==4)four();
if(digit==5)five();
if(digit==6)six();
if(digit==7)seven();
if(digit==8)eight();
if(digit==9)nine();

 DELAY_MS(1);

}



void mux(){
d1_on;digit=thu;comp1();d1_of;
d2_on;digit=ten;comp1();d2_of;

d3_on;digit=unit;comp1();d3_of;


//d3_on;digit=unit;comp1();d3_of;

}


void mdelay()
{
mux();mux();//mux();mux();
mux();mux();mux();mux();
mux();mux();mux();mux();
mux();mux();mux();mux();
mux();mux();mux();mux();
mux();mux();mux();mux();
//mux();mux();mux();mux();
//mux();mux();mux();mux();

}



void getad(){
      int32   result=0;int8 i;
     SET_ADC_CHANNEL(3);
//       for(i=0;i<2;i++)
 //  {
  //   delay_ms(1);
 mux(); mux();mux();mux(); mux();mux();
 result=read_adc();
//}
   val2=result;

  //   value = (int8) (read_adc() * 500)/1023;
//val2 = read_adc ();
  value =   (val2* 5000)/1023;

 thu = (value/1000); mux(); mux();mux();mux(); mux();mux();

 ten = (value/100)%10; mux(); mux();mux();mux(); mux();mux();
 unit = (value/10)%10; mux(); mux();mux();mux(); mux();mux();


/*
putc(thu+48);
putc(ten+48);
putc(unit+48);
 unit = value%10;
putc(unit+48);
putc(10);putc(13);
*/


}

void main ()
{

 DELAY_MS(1);
/*
 //SETUP_ADC_PORTS(NO_ANALOGS);
//   set_tris_a(0);

   set_tris_c(0x00);
   setup_comparator(NC_NC_NC_NC);
   setup_adc_ports(sAN0 | VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);

setup_adc(ADC_CLOCK_INTERNAL );


 set_tris_c(0x00);
     set_tris_a(0xff);
     set_tris_a(0b00011001);
    

  setup_comparator(NC_NC_NC_NC);  
   setup_adc_ports( sAN3 | VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_64);
     set_tris_a(0b00011001);



zero();
//DELAY_MS(1000);

while(1)
 {
// DELAY_MS(10);
//pwmd();

getad();

mdelay();



}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

งานที่2

 เกลียว ชนิดและส่วนต่างๆของเกลียว เกลียว ( Thread)  หมายถึงสันหรือร่องที่เกิดขึ้นบนผิวงานวนไปรอบ ๆจะซ้ายหรือขวาก็ไดด้วยระยะทางที่สม่ำเสมอ เ...