/*
* 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