Using the below code. Is it possible to turn on RC0 for one second and turn it off for one second?
// Timer0
// Prescaler 1:32; TMR0 Preload = 3036; Actual Interrupt Time : 1
// Turn on PORTC.RC0 on for one second and off for one second.
void InitTimer0(){
T0CON = 0x84;
TMR0H = 0x0B;
TMR0L = 0xDC;
GIE_bit = 1;
TMR0IE_bit = 1;
}
void Interrupt(){
if (TMR0IF_bit) {
TMR0IF_bit = 0;
TMR0H = 0x0B;
TMR0L = 0xDC;
}
}
main {
ANSELC = 0;
}
Timer0 One Second Delay PORTC.RCO (Beginner)
Re: Timer0 One Second Delay PORTC.RCO (Beginner)
Hi,
Download and use Timer Calculator software
http://www.mikroe.com/timer-calculator/
Best regards,
Peter
Download and use Timer Calculator software
http://www.mikroe.com/timer-calculator/
Code: Select all
ANSELC = 0; // Set PortC as digital
TRISC = 0; // Set PortC as Output
.
.
.
LATC.F0 = ~LATC.F0; // Alternately change state of RC0
Best regards,
Peter
-
- Posts: 22
- Joined: 09 Nov 2013 17:26
Re: Timer0 One Second Delay PORTC.RCO (Beginner)
Thank you. I did use the Timer Calculator software.
I am apparently incorrectly understanding how the Interrupt works. Why would the below not work?
// Timer0
// Prescaler 1:32; TMR0 Preload = 3036; Actual Interrupt Time : 1
// Turn on PORTC.RC0 on for one second and off for one second.
void InitTimer0(){
T0CON = 0x84;
TMR0H = 0x0B;
TMR0L = 0xDC;
GIE_bit = 1;
TMR0IE_bit = 1;
}
void Interrupt(){
if (TMR0IF_bit) {
TMR0IF_bit = 0;
TMR0H = 0x0B;
TMR0L = 0xDC;
LATC.F0 = ~LATC.F0;
}
}
main {
ANSELC = 0;
TRISC = 0;
while(1) {
}
}
I am apparently incorrectly understanding how the Interrupt works. Why would the below not work?
// Timer0
// Prescaler 1:32; TMR0 Preload = 3036; Actual Interrupt Time : 1
// Turn on PORTC.RC0 on for one second and off for one second.
void InitTimer0(){
T0CON = 0x84;
TMR0H = 0x0B;
TMR0L = 0xDC;
GIE_bit = 1;
TMR0IE_bit = 1;
}
void Interrupt(){
if (TMR0IF_bit) {
TMR0IF_bit = 0;
TMR0H = 0x0B;
TMR0L = 0xDC;
LATC.F0 = ~LATC.F0;
}
}
main {
ANSELC = 0;
TRISC = 0;
while(1) {
}
}
Re: Timer0 One Second Delay PORTC.RCO (Beginner)
Your main code doesn't call the sub procedure "InitTimer0"
So it cannot works
Read the examples in the compiler folder
So it cannot works
Read the examples in the compiler folder
-
- Posts: 22
- Joined: 09 Nov 2013 17:26
Re: Timer0 One Second Delay PORTC.RCO (Beginner)
Thank you for the assistance. I had to type it in different from the Timer Calculator copy/paste but it does work. I guess I will do more reading to figure out the timer. Thank you again.
//Timer0
//Prescaler 1:32; TMR0 Preload = 3036; Actual Interrupt Time : 1
// PIC18F45K22 1 Second Timer
int num = 0;
int second = 0;
int minute = 26;
int hour = 14;
void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0H = 0x0B;
TMR0L = 0xDC;
++num;
++second;
}
}
main() {
ANSELB = 0;
ANSELC = 0;
ANSELD = 0;
TRISB = 0;
TRISC = 0;
TRISD = 0;
LATB =0;
LATC = 0;
LATD = 0;
T0CON = 0x84;
TMR0H = 0x0B;
TMR0L = 0xDC;
GIE_bit = 1;
TMR0IE_bit = 1;
while(1) {
if(num>=1) {
LATB = hour;
LATC = minute;
LATD = second;
num = 0;
}
if(second == 61) {
second = 0;
++minute;
if(minute == 61) {
minute = 0;
++hour;
}
if(hour == 25) {
hour = 0;
}
}
}
}
//Timer0
//Prescaler 1:32; TMR0 Preload = 3036; Actual Interrupt Time : 1
// PIC18F45K22 1 Second Timer
int num = 0;
int second = 0;
int minute = 26;
int hour = 14;
void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0H = 0x0B;
TMR0L = 0xDC;
++num;
++second;
}
}
main() {
ANSELB = 0;
ANSELC = 0;
ANSELD = 0;
TRISB = 0;
TRISC = 0;
TRISD = 0;
LATB =0;
LATC = 0;
LATD = 0;
T0CON = 0x84;
TMR0H = 0x0B;
TMR0L = 0xDC;
GIE_bit = 1;
TMR0IE_bit = 1;
while(1) {
if(num>=1) {
LATB = hour;
LATC = minute;
LATD = second;
num = 0;
}
if(second == 61) {
second = 0;
++minute;
if(minute == 61) {
minute = 0;
++hour;
}
if(hour == 25) {
hour = 0;
}
}
}
}
Re: Timer0 One Second Delay PORTC.RCO (Beginner)
Hi,
For posting code in forum please use code tags, this make better view of your code, also is good to post topic in right thread group.
Read uC datasheet chapters about timers:
PIC18F45K22 datasheet
http://www.microchip.com/wwwproducts/De ... e=en546239
Additionaly read this (based on PIC16F887 but can give you basic):
Chapter 4: Timers
http://www.mikroe.com/chapters/view/5/chapter-4-timers/
Best regards,
Peter
For posting code in forum please use code tags, this make better view of your code, also is good to post topic in right thread group.
Read uC datasheet chapters about timers:
PIC18F45K22 datasheet
http://www.microchip.com/wwwproducts/De ... e=en546239
Additionaly read this (based on PIC16F887 but can give you basic):
Chapter 4: Timers
http://www.mikroe.com/chapters/view/5/chapter-4-timers/
Best regards,
Peter