[SOLVED] LED flash with pic 12f1822

Status
Not open for further replies.

Amanda Lima

Junior Member level 1
Joined
Jul 24, 2021
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
111
Hello people, I really need your help, how to configure the timer0 of pic 12f1822 to flash a led at a frequency of one second using CCS Compiler? **broken link removed**
 
Last edited by a moderator:

Solution
Hello Aussie Susan, This is not a new problem, it's just a continuation of the previous one, this one now depends on the previous one which is to use timer0 to time, so I wanted to make a program to flash an LED' and make the timer work with that, this last program worked in simulation and in practice, but I don't know if the...
Hello people, I really need your help, how to configure the timer0 of pic 12f1822 to flash a led at a frequency of one second using CCS Compiler? **broken link removed**
My problem was not solved, they didn't help me at all, I don't know if they understood me, it was a simple code for those who understand microcontroller code, I delivered the code ready, just wanting to change the type of count that was external from 60Hz to internal using timer0, but I'm very grateful for the help, even if it wasn't helpful. Thank you stay with God.
 
Last edited by a moderator:

Your crystal is 32MHZ.
Set TMR1 to use the internal clock as its source,
Set TMR1 pre-scaler to 8
Load the value 0xBEE9 in to TMR1. (TMR1H = 0xBE; TMR1L = 0xE9
Enable TMR1 interrupts and then GIE.

You now have an interrupt after 0.016663 seconds (= 60.01Hz)

Inside the ISR, reload TMR1 with the same value again then set a variable, lets call it "SixtyHz".

Now in the main() code loop keep checking to see if "SixtyHz" has been set, if it has, reset it and us it in the same way you used your external 60HZ signal.

Brian.
 

Hi, I made the code, I'm going to change the old timed photocell code.
I don't understand why this message appeared, since I'm using pic 12f1822 and not this [PIC16 CORE] PC=0x0074. TRISA instruction is deprecated for PIC121822. [U1], do you know what it means? and about turning on an LED at the grid zero crossing using pic 12f1822
Code:
#include <main.h>
int contador = 0;
#INT_TIMER1
void  TIMER1_isr(void)
{
contador++;
if(contador==1)
{
output_toggle(pin_a5);

contador = 0;
}
set_timer1(3036); // 0,5 segundo
clear_interrupt(int_timer1);
   }

void main()
{
   setup_adc_ports(sAN1|sAN2|sAN3);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);      //524 ms overflow
   set_timer1(3036);

   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

//0,5s = 1us x 8 x(65536- carga TRM1)
// carga TRM1 = 65536 - 500000/8us
// carga TRM1 = 65536-62500
//carga TRM1 = 3036



   while(TRUE)
{
  }
    }
 
Last edited by a moderator:

Hi, I made the code, I'm going to change the old timed photocell code.
I don't understand why this message appeared, since I'm using pic 12f1822 and not this [PIC16 CORE] PC=0x0074. TRISA instruction is deprecated for PIC121822. [U1], do you know what it means? and about turning on an LED at the grid zero crossing using pic 12f1822
Code:

Code:
#include <main.h>
int contador = 0;
#INT_TIMER1
void  TIMER1_isr(void)
{
contador++;
if(contador==1)
{
output_toggle(pin_a5);

contador = 0;
}
set_timer1(3036); // 0,5 segundo
clear_interrupt(int_timer1);
   }

void main()
{
   setup_adc_ports(sAN1|sAN2|sAN3);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);      //524 ms overflow
   set_timer1(3036);

   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

//0,5s = 1us x 8 x(65536- carga TRM1)
// carga TRM1 = 65536 - 500000/8us
// carga TRM1 = 65536-62500
//carga TRM1 = 3036



   while(TRUE)
{
  }
    }
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…