martes, 6 de junio de 2017

Switch With dsPIC30F4013


Diagram:
Code (XC16 Compiler):
#include <xc.h>
#include <libpic30.h>
 
// Configuration settings
_FOSC(CSW_FSCM_OFF & FRC_PLL16); // Fosc=16x7.5MHz, i.e. 30 MIPS
_FWDT(WDT_OFF);                  // Watchdog timer off
_FBORPOR(MCLR_DIS);              // Disable reset pin
 
int main(void)
{
    // Make RD0 a digital output and RD1 as input
    _TRISD0 = 0;
    _TRISD1 = 1;
    
    // Blink LED on RD0
    while(1)
    {
        if (_RD1 == 1) {
        _LATD0 = 1;
        __delay32(15000000);

        }
        else {
        _LATD0 = 0;
        __delay32(15000000);
        }
    }
}


_______________________________________________________________________

  Projects With dsPIC30F2010 And dsPIC30F4013

http://guillengap.blogspot.com/2016/07/ebook-projects-with-dspic30f2010-and.html


https://www.amazon.com/dp/B01F4YBCHG

https://www.amazon.com/Guillermo%20Perez/e/B01EZOTUVQ/

guillengap@gmail.com

sábado, 3 de junio de 2017

Thermostat With PIC16F887


Diagram:

Code:

#include <16f887.h>
#device ADC=10       
#FUSES XT,NOWDT
#use delay(clock = 4000000)
#define use_portb_lcd TRUE
#include 
#use fast_IO(C)      

#byte trisb=0x86
#byte portb=0x06
#byte trisc=0x87
#byte portc=0x07

void main()
{
   trisc=0b00000000; 
   bit_clear(TRISC,0);         // C0 as output
   bit_clear(TRISC,1);         // C1 as output   
   int16 q;
   float p;
   setup_adc_ports(sAN0);          //Channel 0 
   setup_adc(ADC_CLOCK_DIV_32);    //Clock RC
do
{
     set_adc_channel(0);           // Channel 0
      delay_us(20);
      q = read_adc();                 
      p = 5.0 * 100 * q / 1024.0;           //Conversion
      lcd_init(); // start LCD
      lcd_gotoxy(5,1);
      printf(lcd_putc, "\f      TEMPERATURE  ");
      printf(lcd_putc, "\n        %01.2f C", p);

      if (p >= 30)
      {
         output_high(PIN_C0);                            //turn on FAN
         output_high(PIN_C1);                            //turn on LED        
         delay_ms(500);
      }
      else          
      {
         output_low(PIN_C0);                             //turn off FAN
         output_low(PIN_C1);                             //turn off LED   
         delay_ms(500);
      }
}
while(true);
}


_______________________________________________________________________

 Projects With Microcontrollers And PICC

http://guillengap.blogspot.com/2016/07/ebook-projects-with-microcontrollers.html


https://www.amazon.com/dp/B01EZOMGZS

https://www.amazon.com/Guillermo%20Perez/e/B01EZOTUVQ/

guillengap@gmail.com