Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

izrada countdown timer-a

[es] :: Elektronika :: Mikrokontroleri :: izrada countdown timer-a

[ Pregleda: 2994 | Odgovora: 8 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

conver
Milos Milutinovic
Paracin

Član broj: 226436
Poruke: 112
212.200.65.*



+1 Profil

icon izrada countdown timer-a10.10.2010. u 14:05 - pre 164 meseci
Zdravo svima! Potrebna mi je pomoc u izradi naj obicnijeg vremenskog brojaca! Dakle hocu da mi se na LCD-u posle pokretanja brojaca ili countdown timer-a,ispisuje 60,59,58,57... do 0 sekundi. Dakle ne poznajem rad sa tajmerom pa bi mi svaka pomoc dobro dosla... hvala!
Pic 16f887 na 4mhz i 2x16 char lcd
 
Odgovor na temu

vukboban
Boban Vukovic
PANCEVO

Član broj: 116735
Poruke: 250
178.218.202.*



+11 Profil

icon Re: izrada countdown timer-a10.10.2010. u 17:40 - pre 164 meseci
Za ovo ti ne treba tajmer,nego samo obicno kasnjenje.
Uzmes neku promenljivu (x) ,dodelis joj vrednost (u tvom slucaju 60), posaljes vrednost na displej,cekas da se pritisne START taster.

onda napravis neku petlju u kojoj treba da stoji :
DELAY_MS(1000) ;
X=X-1;
saljes X na displej;

i sve tako dok x nije jednako nula.
 
Odgovor na temu

plc
vladislav
Velika Plana

Član broj: 266870
Poruke: 107
*.dynamic.isp.telekom.rs.

Sajt: www.industrijasrbije.rs


+1 Profil

icon Re: izrada countdown timer-a10.10.2010. u 17:46 - pre 164 meseci
Ne razumem, treba ti hex?
Imas li programator za pic-a,mozes sve na tenane na sajtu mikroelektronike.
http://www.mikroe.com/eng/home/index/
Imaju gotove primere kad skines compiler (moze do 2k koda).
Pozz
 
Odgovor na temu

conver
Milos Milutinovic
Paracin

Član broj: 226436
Poruke: 112
212.200.65.*



+1 Profil

icon Re: izrada countdown timer-a11.10.2010. u 06:51 - pre 164 meseci
Ne,ne treba mi hex fajl :)
zelim da ovladam radom tajmera, dakle da naucim kako da ga pokrenem u CCSu i generisem interupt svake sekunde i posaljem podatak na LCD!
 
Odgovor na temu

bantu

Član broj: 38670
Poruke: 305
89.111.240.*



+27 Profil

icon Re: izrada countdown timer-a11.10.2010. u 07:39 - pre 164 meseci
Šta će da se desi kada istekne vrijeme, da ne praviš neku bombu?
:)
 
Odgovor na temu

conver
Milos Milutinovic
Paracin

Član broj: 226436
Poruke: 112
212.200.65.*



+1 Profil

icon Re: izrada countdown timer-a12.10.2010. u 08:54 - pre 164 meseci
Nista, nek krene opet od 60 sec!
 
Odgovor na temu

plc
vladislav
Velika Plana

Član broj: 266870
Poruke: 107
*.dynamic.isp.telekom.rs.

Sajt: www.industrijasrbije.rs


+1 Profil

icon Re: izrada countdown timer-a12.10.2010. u 15:44 - pre 164 meseci
/*
* Project name:
Timer0_Interrupt (Using Timer0 to obtain interrupts)
* Copyright:
(c) Mikroelektronika, 2008.
* Revision History:
20080930:
- initial release;
* Description:
This code demonstrates how to use Timer0 and it's interrupt.
Program toggles LEDs on PORTB.
* Test configuration:
MCU: PIC16F887
http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf
Dev.Board: EasyPIC6
http://www.mikroe.com/eng/prod...7/easypic6-development-system/
Oscillator: HS, 08.0000 MHz
Ext. Modules: -
SW: mikroC PRO for PIC
http://www.mikroe.com/eng/products/view/7/mikroc-pro-for-pic/
* NOTES:
- Turn on LEDs on PORTB switch SW9.2 (board specific).
*/



unsigned cnt;

void interrupt() {
if (TMR0IF_bit) {
cnt++; // increment counter
TMR0IF_bit = 0; // clear TMR0IF
TMR0 = 96;
}
}

void main() {
OPTION_REG = 0x84; // Assign prescaler to TMR0
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISB = 0; // PORTB is output
PORTB = 0xFF; // Initialize PORTB
TMR0 = 96; // Timer0 initial value
INTCON = 0xA0; // Enable TMRO interrupt
cnt = 0; // Initialize cnt

do {
if (cnt >= 400) {
PORTB = ~PORTB; // Toggle PORTB LEDs
cnt = 0; // Reset cnt
}
} while(1);
}

to ti tajmer TMR0...

LCD PRIMER


// LCD module connections
sbit LCD_RS at LATD2_bit; // for writing to output pin always use latch (PIC18 family)
sbit LCD_EN at LATD3_bit; // for writing to output pin always use latch (PIC18 family)
sbit LCD_D4 at LATD4_bit; // for writing to output pin always use latch (PIC18 family)
sbit LCD_D5 at LATD5_bit; // for writing to output pin always use latch (PIC18 family)
sbit LCD_D6 at LATD6_bit; // for writing to output pin always use latch (PIC18 family)
sbit LCD_D7 at LATD7_bit; // for writing to output pin always use latch (PIC18 family)

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

char txt1[] = "mikroElektronika";
char txt2[] = "BigPIC6";
char txt3[] = "Lcd4bit";
char txt4[] = "example";

char i; // Loop variable

void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}

void main(){

ADCON1 |= 0x0F; // Configure AN pins as digital
CMCON |= 7; // Disable comparators

Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

Lcd_Out(1,6,txt3); // Write text in first row
Lcd_Out(2,6,txt4); // Write text in second row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display

Lcd_Out(1,1,txt1); // Write text in first row
Lcd_Out(2,5,txt2); // Write text in second row
Delay_ms(2000);

// Moving text
for(i=0; i<4; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}

while(1) { // Endless loop
for(i=0; i<7; i++) { // Move text to the left 7 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}

for(i=0; i<7; i++) { // Move text to the right 7 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}

}
}

ovo su primeri pa ti nesto iskombinuj....

Slicno je i u css-u

Pozz
 
Odgovor na temu

conver
Milos Milutinovic
Paracin

Član broj: 226436
Poruke: 112
212.200.65.*



+1 Profil

icon Re: izrada countdown timer-a13.10.2010. u 07:37 - pre 164 meseci
hvala plc

evo sta sam ja izmuvao... ali opet ne radi! Na lcd mi ispisuje samo 0 ili 1
malo sam prepisivao, malo budzio... ali nece!


#include "16F887.h"
#use delay(clock=4MHz)

#include "LCD.c"

#define XTAL_FREQUENCY 4000000
#define TIMER1_FREQUENCY (XTAL_FREQUENCY / 4) // 1 clock tick = 1 instr. cycle = crystal frequency / 4
int32 Ticker;
int8 seconds;

void Initialize_RTC(void)
{
Ticker = TIMER1_FREQUENCY; // initialize clock counter to number of clocks per second
setup_timer_1( T1_INTERNAL | T1_DIV_BY_4 ); // initialize 16-bit Timer1 to interrupt
// exactly every 65536 clock cycles
// (about 76 times per second)
enable_interrupts(INT_TIMER1); // Start RTC
}
void TIMER1_isr()
{
Ticker -= 65536; // Decrement ticker by clocks per interrupt
if ( Ticker < 65536 ) // If second has expired
{ Ticker += TIMER1_FREQUENCY; // Increment ticker by clocks per second
seconds++; // Increment number of seconds
}
}
void main(){


enable_interrupts(INT_TIMER1); //unmask Timer1 overflow interrupt
enable_interrupts(global); //enable all unmasked interrupts

lcd_init();
delay_ms(100);

while(1){
if(input(PIN_E0))
{
Delay_ms(500);
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc,"%d"seconds);
}
}

}
 
Odgovor na temu

plc
vladislav
Velika Plana

Član broj: 266870
Poruke: 107
*.dynamic.isp.telekom.rs.

Sajt: www.industrijasrbije.rs


+1 Profil

icon Re: izrada countdown timer-a13.10.2010. u 14:43 - pre 164 meseci
Da... vidim samo da si ispustio promenljivu .... f ....

Molim te ne zameri mi ako sam negde pogresio davno sam ovo radio .
Ovde ima od prilike ono sta ti treba samo fali konfiguracija za LCD i proracun sekunde u interaptu.


unsigned cnt=0;//globalne promenljive
char sekunde=0;//


void interrupt() { // interapt TMRO
if (TMR0IF_bit) {
cnt++; // increment counter
TMR0IF_bit = 0; // clear TMR0IF
TMR0 = 96;
}
if (cnt >= 400) // moras prpracunati koliko je 1sec.
{
sekunde--; // Toggle PORTB LEDs
cnt = 0; // Reset cnt
}
}

void main() {
OPTION_REG = 0x84; // Assign prescaler to TMR0
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISB = 0x01; // PORTB is output
PORTB = 0x00; // Initialize PORTB
TMR0 = 96; // Timer0 initial value
INTCON = 0x00; // TMRO interrupt
cnt = 0; // Initialize cnt
// Lcd_Init(); // Initialize LCD
//// Lcd_Cmd(_LCD_CLEAR); // Clear LCD
// Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Delay_ms(1000);

while(1)
{

while (PORTB.f0==1 ) ; //pritisak taster portb.f0
while(PORTB.f0==0) //prilikom otpusta dodeljujes vrednost sekundi i ukljucujes interapt
{
sekunde=60;
INTCON = 0xA0; // Enable TMRO interrupt
portb.f1=1;// Relej=1;
}
if(sekunde==0) // kada istekne 60 sec. stopiraj intrapt
{
INTCON = 0x00; // Disable TMRO interrupt
portb.f1=0;// Relej=0;
}
///// Lcd_Out(1, 1, "sekunde");
///// Lcd_Out(2,1,sekunde);
}
}
 
Odgovor na temu

[es] :: Elektronika :: Mikrokontroleri :: izrada countdown timer-a

[ Pregleda: 2994 | Odgovora: 8 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.