PIC zaciatocnik
Rosko, Peter
Peter.Rosko@siemens.com
Úterý Únor 3 12:23:02 CET 2009
zdravim zase,
tak som vylucil chybny chip, dnes som kupil novy PIC16f877a a robi to
iste
na osciloskope a na RA0 vidim 1 dlhu ako ma byt, takze cely procesor
bezi na tych 14MHz, potom sa to cele opakuje s periodou 20msec
kod je dolu, wdt sa resetuje este predtym ako sa povoli prerusenie...
#include <htc.h>
#include <stdio.h>
#include <string.h>
#include "usart.h"
#include "onewire.h"
#include "test.h"
__CONFIG(HS & WDTEN & PWRTDIS & BORDIS & UNPROTECT);
#define _XTAL_FREQ 14745600
volatile unsigned char tim1111us;
unsigned char tim10ms, tim100ms;
volatile unsigned int fff;
void timer_init(void);
void main(void)
{
CLRWDT();
TRISA0 = 0;
RA0 = 0;
//__delay_ms(1);
RA0 = 1;
RA0 = 0;
//__delay_ms(1);
CLRWDT();
while (1) CLRWDT();
timer_init();
// oneWireInit();
// init_comms();
// test_init();
// printf("Welcome\r");
ei();
while(1)
{
CLRWDT();
// ow_task();
// usart_rx_task();
// test_task();
if (tim100ms >= 10)
{
test_task_param |= TEST_LED_TOGGLE;
tim100ms = 0;
}
if (tim10ms >= 10)
{
ow_task_param |= OW_RUN;
tim100ms++;
tim10ms = 0;
}
di();
if (tim1111us >=9 )
{
tim10ms++;
tim1111us = 0;
}
ei();
}
}
void interrupt isr(void)
{
if (TMR1IE && TMR1IF)
{
TMR1IF=0;
}
if (TMR0IE && TMR0IF)
{
tim1111us++;
TMR0IF = 0;
}
if (RCIE && RCIF)
{
char received_char;
received_char = RCREG;
usart_rx_buff[usart_rx_buff_cntr++ & USART_RX_BUFF_MASK]
= received_char;
if (received_char == 0x0D) //'CR' - Enter
{
usart_rx_task_param |= CHECK_RX_BUFF;
usart_rx_buff[usart_rx_buff_cntr] = 0; //ends string
usart_rx_buff_cntr = 0;
}
// RCIF = 0;
}
}
//timer1
void timer_init(void)
{
TMR1CS = 0;
TMR1ON = 1;
T1OSCEN = 1;
TMR1IE = 1;
PEIE = 1;
TMR0IE = 1;
T0CS = 0;
PSA = 0;
PS0 = 1;
PS1 = 1;
PS2 = 0;
}
Další informace o konferenci Hw-list