Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16f1503 to 16f676 conversion

Status
Not open for further replies.

sahu

Member
hi everyone
Today I'm facing problem with 16f676 adc reading.
Actually i want convert micro controller. That code works fine with 16f1503 but when i convert it 16f676, adc readind reading function not work.
16f1503.h
Code:
#include <16F1503.h> 
#device ADC=11 

//#FUSES WDT                      //Watch Dog Timer 
#FUSES NOMCLR                   //Master Clear pin used for I/O 
#FUSES PROTECT                  //Code protected from reads 
#FUSES BORV25                   //Brownout reset at 2.5V 
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O 

#use delay(internal=4000000,restart_wdt) 
//#use rs232(baud=9600,parity=N,xmit=PIN_C4,rcv=PIN_C3,bits=8,stream=PORT1) 

#use FIXED_IO( A_outputs=PIN_A5,PIN_A2,PIN_A1 ) 
#use FIXED_IO( C_outputs=PIN_C5,PIN_C3,PIN_C2,PIN_C1,PIN_C0 )
16f1503.c
Code:
#include <sta_1503.h> 

#include <math.h> 

void main() 
{ 
    
init_peripheral(); 
/******Timer Init*******/ 
      
      output_low(RLY1_TMR); output_low(High_Low_LED);output_low(TIMER_LED); 
      setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //524 ms overflow 
      enable_interrupts(INT_TIMER1); 
      enable_interrupts(GLOBAL); 
      delay_ms(1);      
/******* End of ADC Init*******/  

/******* Start of Peripherial *******/ 
      
      output_high(Buzzer);output_low(TIMER_LED);output_low(RLY1_TMR); 
      output_low(RLY2);output_low(RLY3);output_low(RLY4);output_low(RLY5); 
      output_low(High_Low_LED); 
      system_tick = 0; 
    
   /******* End of Peripherial *******/ 
   delay_ms(10); 
   relay_voltage();  output_low(Buzzer); 
  while(TRUE)       //Master Loop 
   {   ///to do something 
}} 
/*****************************************/ 
//Reading A/C Voltage 
/*****************************************/ 

long read_ac_voltage(void) 
{ 
unsigned char i; 
long adc_value; 
long peak_value=0; 

set_adc_channel(0); 
delay_ms(1); 
         for(i=0;i<=40;i++) 
         { 
            adc_value = read_adc(); 
            if(adc_value > peak_value) 
            { 
             peak_value = adc_value; 
            } 
            
            delay_us(500); 
            
         } 
          
         peak_value = (peak_value*0.266); 
         return peak_value; 
} 


long read_timer_value(void) 
{ 

            long adc_value; 
            set_adc_channel(3); 
            delay_ms(1); 
            adc_value = read_adc(); 
            return adc_value; 
    
} 
void init_peripheral(void) 
{ 
    
   set_tris_a(0x08); // RA3 TMR_relay reset 
   set_tris_c(0x10); // RC4 reset 
    
   /*******ADC*******/ 
   setup_comparator(NC_NC_NC_NC); 
   setup_adc(ADC_CLOCK_DIV_32); 
   setup_adc_ports( sAN0|sAN3| VSS_VDD);    //RA4 as timer value adc 
   setup_comparator(NC_NC_NC_NC); 
   set_tris_c(0x10);  // Set Pin RC4 as input, Timer reset 
   port_a_pullups(0x08);//pull up on port a3 
   port_c_pullups(0x10);//pull up on port c4 

   /******* End of ADC Init*******/ 
}
Now pls guide me about 16f676 !!!!!!!
i do as for 16f676
Code:
/#include <16F1503.h> 
//#device ADC=11 

#include <16F676.h> 
#device ADC=10 
/* 
//#FUSES WDT                      //Watch Dog Timer 
#FUSES NOMCLR                   //Master Clear pin used for I/O 
#FUSES PROTECT                  //Code protected from reads 
//#FUSES BORV25                   //Brownout reset at 2.5V 
//#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O 
**/ 
//#FUSES WDT                    //No Watch Dog Timer 
#FUSES INTRC_IO                 //Internal Oscillator @ 4 Mhz 
//#FUSES BROWNOUT               //No brownout reset 
#FUSES NOMCLR              //No brownout reset 
#FUSES PROTECT          //Code protected from reads 

//#use delay(internal=4000000,restart_wdt) 
//#use rs232(baud=9600,parity=N,xmit=PIN_C4,rcv=PIN_C3,bits=8,stream=PORT1) 
#use delay(clock=4000000)      // 4 Mhz Clock 
#rom 0x3FF = {0x3480}[/code
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top