mod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_counter
mod_vvisit_counterToday6
mod_vvisit_counterYesterday12
mod_vvisit_counterThis week44
mod_vvisit_counterLast week83
mod_vvisit_counterThis month233
mod_vvisit_counterLast month267
mod_vvisit_counterAll days23012

We have: 1 guests online
Your IP: 10.2.31.21
Mozilla 5.0, 
Today: Απρ 26, 2024

Πρόσφατα άρθρα

Προγραμματισμός Μικροελεγκτών PIC σε γλώσσα C

Σύντομα θα ακολουθήσουν οδηγίες και σχόλια!

Πολύ καλό Link : http://www.microchipc.com

 

 

/* This is a simple demo project written for use with
 * the HI-TECH Software PICC compiler. It may be compiled
 * and run on the Microchip PICDEM 2 PLUS DEMO BOARD.
 * Features demonstrated include driving the LCD display and
 * the A2D converter.
 
 Additional files required for this demo are included in the
 PIC\SAMPLES directories:
 DELAY\delay.c
 DELAY\delay.h
 lcd.c
 lcd.h
 */

#include <pic.h>
#include <stdio.h>
#include "lcd.h"

/* this is the maximum value of an A2D conversion. */
#define MAXVOLTAGE 5
#define SENSITIVITYMASK    0xFC    // Reduce precision of A2D result

void init(void){
    lcd_init(FOURBIT_MODE);
    ADON=1;    /* enable A2D converter */
    ADIE=0;    /* not interrupt driven */
    ADCON1=0x0E;
    ADCON0=1;
    TRISB=0x00;    // Set PORTB in output mode
    T1CON=0x31;    // turn on timer 1
    TMR1IE=1;    // timer 1 is interrupt enabled
    PEIE=1;        // enable peripheral interrupts
    GIE=1;        // turn on interrupts
}

void interrupt isr(void){
    if(TMR1IE && TMR1IF){
        PORTB++;
        TMR1IF=0;
    }
}

void main(void){
    unsigned char last_value;
    unsigned char volts;
    unsigned char decivolts;
    unsigned char outString[20];

    init();
    lcd_puts("Adust the");
    lcd_home2();    // select line 2
    lcd_puts("potentiometer");    

    while(1){
        GODONE=1;
        while(GODONE)continue;
        ADIF=0;
        // Mask off the lower two bits as this level of precision
        // is wasted as we're only showing 0.1 volt increments.
        // This reduces unneccesary updates to the LCD.
        if((ADRESH&SENSITIVITYMASK)!=(last_value&SENSITIVITYMASK))
        {
            volts=0;
            for(decivolts=(ADRESH*10*MAXVOLTAGE/255);decivolts>=10;decivolts-=10)
                volts++;
            lcd_clear();
            sprintf(outString,"A2D = %d.%d volts",volts,decivolts);
            lcd_puts(outString);
        }
        last_value=ADRESH;
    }
}