Jump to content
ELFORUM - Forumul electronistilor

Cond in Hitech C(sau XC) ptr PWM


lama

Recommended Posts

  • Replies 1
  • Created
  • Last Reply

Raspund tot eu cu un mic exemplu(dupa manual).

rezolutie este pe 8 deci un maxim de 255.

Apasand pe buton se mareste sau se micsoreaza duty.

 

 

/*************************************************************************                                                                       **   Processor:     16F690                                              **   Pin assignments:                                                    **  RA0 - ICSPDAT **  RA1 - ICSPCLK **  RA2 - SCLK **  RA3 - MCLR **  RA4 - Ain **  RC5 - Test Led **  RB4 - SCE **  RB5 - Buton 1 **  RB6 - Buton 2 **  RB7 - Buton 3 **  RC0 - DNK **  RC1 - D/C **  RC2 - RST **  RC6 - Vin **************************************************************************/#include <pic.h> #include <stdlib.h>#include <stdio.h>//#include <limits.h>#include "5110.h"#define CLK RA2 #define RST RC2 __CONFIG(FOSC_INTRCIO  & // INTOSC oscillator internalWDTE_OFF & // Watchdog timer disabledPWRTE_OFF & // Power up timer enabledBOREN_OFF & // Brown-out detect modes disabledCPD_OFF & // Protection of program code off disabledCP_OFF & // Protection of data block disabledMCLRE_OFF); // Master clear reset#define _XTAL_FREQ 8000000 /* Crystal frequency in MHz */#define cit_delay 65#define Led_test RC5#define ON 1#define OFF 0void wait_button_release(unsigned char );void set_volt_step(void);void scrie_eeprom(unsigned int , unsigned char );unsigned int citeste_eeprom( unsigned char );void init(void);void afisare_volt(void );void afisare_amp(void );void voltage(void);void amp(void);//partea de butoane#define  UP RB7#define  SETUP RB6#define  DOWN RB5unsigned char db_cnt;void wait_button_release(unsigned char care_buton){        // wait until button released ( state high), debounce by counting:        for (db_cnt = 0; db_cnt <= 10; db_cnt++) {         __delay_ms(1);          // sample every 1 ms            switch(care_buton){case 1: if (UP == 0) db_cnt = 0;  break;case 2: if (SETUP == 0) db_cnt = 0;  break;case 3: if (DOWN == 0) db_cnt = 0;  break;      }    } }void init(void){OSCCON=0x70; /* Select 8 Mhz internal clock */TRISA = 0b00010000; TRISB = 0b11100000; //RB7,6,5 ButtonsTRISC = 0b00000000; // PORTC = 0; PORTB = 0; PORTA = 0; ANSEL = 0b00000000;  // Set AN3 as analog imputANSELH = 0b00000000;        // Set PORT AN8 analog imputCM1CON0 = 0; CM2CON0 = 0; // disable comparator 2 (RC0, RC1, RC4 usable)C1ON=0; // Turn off Comparators C2ON=0;  CCP1CON=0b00001100;  // Single PWM mode; P1A, P1C active-high; P1B, P1D active-high  CCPR1L=0;            // Start with zero Duty Cycle    T2CON=0b00000101;    // Postscale: 1:1, Timer2=On, Prescale = 1:4  PR2=0x65;            // Frequency: 4.90 kHz - resolution 8 bits  TMR2=0;              // Start with zero Counter}void main(void){ unsigned int ipwm;unsigned char buf[16];init();   CLK=0;              // SLED4C clock pin must idle lowinit_nokia();__delay_ms(250);nokia_build_DDRAM(); // clear the displaynokia_gotoxy(0,0);nokia_printmessage("PWM hardware");   ipwm=0;while(1){if(UP == 0 ){ipwm++;    CCPR1L=ipwm;sprintf(buf, "Duty: %d", ipwm);nokia_gotoxy(0,3);nokia_printmessage(&buf);wait_button_release(1);} if(DOWN == 0 ){ipwm--;    CCPR1L=ipwm;sprintf(buf, "Duty: %d", ipwm);nokia_gotoxy(0,3);nokia_printmessage(&buf);wait_button_release(3);} /* //e setup apasat??if(SETUP == 0 ){nokia_build_DDRAM(); // clear the displaynokia_gotoxy(0,0);nokia_printmessage("Setup Pressed");nokia_gotoxy(0,1);nokia_printmessage("Waitting for release");wait_button_release(2);nokia_build_DDRAM(); // clear the display} __delay_ms(500);*/}}

exemple de cod se pun in [/code] sau in fisiere sa putem intelege ceva

Sofian

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.




×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines