[an error occurred while processing this directive]
|
/*********************************************
This program was produced by the
CodeWizardAVR V1.23.6b Standard
Automatic Program Generator
© Copyright 1998-2002 HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro , hpinfotech@xnet.ro
Chip type : AT90S8515
Clock frequency : 4,000000 MHz
Memory model : Small
Internal SRAM size : 512
External SRAM size : 0
Data Stack size : 128
*********************************************/
#include <90s8515.h> #define term_VDD 2 #define RXB8 1 #define FRAMING_ERROR (1< // UART Receiver buffer // UART Receiver interrupt service routine #ifndef _DEBUG_TERMINAL_IO_ // UART Transmitter buffer // UART Transmitter interrupt service routine #ifndef _DEBUG_TERMINAL_IO_ // returns 0x80 if parity of c is even // Declare your global variables here void reset_1_wire (void); void main(void) // Input/Output Ports initialization // Port B initialization // Port C initialization // Port D initialization // Timer/Counter 0 initialization // Timer/Counter 1 initialization // External Interrupt(s) initialization // Timer(s)/Counter(s) Interrupt(s) initialization // UART initialization // Analog Comparator initialization // Global enable interrupts while (1) delay_ms (100); while (ready_1_wire) if (incomm == 'i') if (incomm == 'w') if (incomm == 'r') if (incomm == 'G') if (incomm == 't') if (incomm == '0') if (incomm == '1') void reset_1_wire (void) void mode_toggle (void) PORTD.term_1_wire = 1; void command_1_wire (unsigned char command, unsigned char data) buf_write_1_wire = command; void read_1_wire (void) DDRD.term_1_wire = 1; void write_1_wire (void)
E-mail:
info@telesys.ru
#include
#define term_1_wire 3
#define TXB8 0
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define RX_BUFFER_SIZE 8
char rx_buffer[RX_BUFFER_SIZE];
unsigned char rx_wr_index,rx_rd_index,rx_counter;
// This flag is set on UART Receiver buffer overflow
bit rx_buffer_overflow;
#pragma savereg-
interrupt [UART_RXC] void uart_rx_isr(void)
{
char status,ctrl,data;
#asm
push r26
push r27
push r30
push r31
in r26,sreg
push r26
#endasm
status=USR;
ctrl=UCR;
data=UDR;
if (status & (FRAMING_ERROR | DATA_OVERRUN));
else if (parity_even(data)==((ctrl<<(7-RXB8)) & 0x80))
{
rx_buffer[rx_wr_index]=data;
if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
if (++rx_counter == RX_BUFFER_SIZE)
{
rx_counter=RX_BUFFER_SIZE;
rx_buffer_overflow=1;
};
};
#asm
pop r26
out sreg,r26
pop r31
pop r30
pop r27
pop r26
#endasm
}
#pragma savereg+
// Get a character from the UART Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter==0);
data=rx_buffer[rx_rd_index];
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
#asm("cli")
--rx_counter;
#asm("sei")
return data;
}
#pragma used-
#endif
#define TX_BUFFER_SIZE 8
char tx_buffer[TX_BUFFER_SIZE];
unsigned char tx_wr_index,tx_rd_index,tx_counter;
#pragma savereg-
interrupt [UART_TXC] void uart_tx_isr(void)
{
char data;
#asm
push r26
push r27
push r30
push r31
in r26,sreg
push r26
#endasm
if (tx_counter)
{
--tx_counter;
data=tx_buffer[tx_rd_index];
UCR&=~(1<
UDR=data;
if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0;
};
#asm
pop r26
out sreg,r26
pop r31
pop r30
pop r27
pop r26
#endasm
}
#pragma savereg+
// Write a character to the UART Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter == TX_BUFFER_SIZE);
if (tx_counter || ((USR & DATA_REGISTER_EMPTY)==0))
{
tx_buffer[tx_wr_index]=c;
if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0;
#asm("cli")
++tx_counter;
#asm("sei")
}
else UDR=c;
}
#pragma used-
#endif
// returns 0 if parity of c is odd
#pragma warn-
unsigned char parity_even(unsigned char c)
{
#asm
ld r30,y
mov r31,r30
swap r30
eor r30,r31
mov r31,r30
lsl r31
lsl r31
eor r30,r31
mov r31,r30
lsl r30
eor r30,r31
andi r30,0x80
#endasm
}
#ifdef _WARNINGS_ON_
#pragma warn+
#endif
// Standard Input/Output functions
#include
unsigned char ready_1_wire;
unsigned char buf_read_1_wire, buf_write_1_wire;
void mode_toggle (void);
void command_1_wire (unsigned char command, unsigned char data);
void read_1_wire (void);
void write_1_wire (void);
{
// Declare your local variables here
unsigned char incomm, th, tl, rs;
// Port A initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
PORTA=0x00;
DDRA=0x00;
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
PORTB=0x00;
DDRB=0x00;
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
PORTC=0x00;
DDRC=0x00;
// Func0=In Func1=In Func2=Out Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=1 State3=T State4=T State5=T State6=T State7=T
PORTD=0x04;
DDRD=0x04;
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// INT0: Off
// INT1: Off
GIMSK=0x00;
MCUCR=0x00;
TIMSK=0x00;
// Communication Parameters: 8 Data, 1 Stop, Even Parity
// UART Receiver: On
// UART Transmitter: On
// UART Baud rate: 19200
UCR=0xDC;
UBRR=0x0C;
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
#asm("sei")
{
// Place your code here
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
}
{
incomm = getchar ();
{
if (!PIND.term_VDD)
{
PORTD.term_VDD = 1;
printf ("VDD DS1821 now is ON\r\n");
delay_ms (100);
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
else
{
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
printf ("Input DS1821 TH \r\n",);
th = getchar ();
printf ("Input DS1821 TL \r\n",);
tl = getchar ();
printf ("Input DS1821 RS \r\n",);
rs = getchar ();
printf ("Ok\r\n");
}
{
if (!PIND.term_VDD)
{
PORTD.term_VDD = 1;
printf ("VDD DS1821 now is ON\r\n");
delay_ms (100);
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
else
{
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
command_1_wire (0x01, th);
delay_ms (100);
command_1_wire (0x02, tl);
delay_ms (100);
command_1_wire (0x0c, rs);
delay_ms (100);
printf ("Ok\r\n");
}
{
if (!PIND.term_VDD)
{
PORTD.term_VDD = 1;
printf ("VDD DS1821 now is ON\r\n");
delay_ms (100);
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
else
{
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
command_1_wire (0xa1, 0x00);
printf ("DS1821 TH =%3d\r\n", buf_read_1_wire);
command_1_wire (0xa2, 0x00);
printf ("DS1821 TL =%3d\r\n", buf_read_1_wire);
command_1_wire (0xac, 0x00);
printf ("DS1821 RS =%3X\r\n", buf_read_1_wire);
}
{
if (!PIND.term_VDD)
{
PORTD.term_VDD = 1;
printf ("VDD DS1821 now is ON\r\n");
delay_ms (100);
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
{
if (!PIND.term_VDD)
{
PORTD.term_VDD = 1;
printf ("VDD DS1821 now is ON\r\n");
delay_ms (100);
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
else
{
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
command_1_wire (0xee, 0x00);
delay_ms (1500);
command_1_wire (0x22, 0x00);
command_1_wire (0xaa, 0x00);
printf ("Current Temperature =%3d\r\n", buf_read_1_wire);
}
{
PORTD.term_VDD = 0;
printf ("VDD DS1821 now is OFF\r\n");
}
{
PORTD.term_VDD = 1;
printf ("VDD DS1821 now is ON\r\n");
delay_ms (100);
reset_1_wire ();
if (!ready_1_wire)
{
mode_toggle ();
printf ("DS1821 Mode Toggle\r\n");
delay_ms (100);
}
}
}
}
}
{
DDRD.term_1_wire = 1;
delay_us (550);
DDRD.term_1_wire = 0;
delay_us (45);
ready_1_wire = ~PIND.term_1_wire;
delay_us (45);
ready_1_wire |= ~PIND.term_1_wire;
delay_us (550);
}
{
unsigned char i;
DDRD.term_1_wire = 1;
PORTD.term_VDD = 0;
delay_us (1);
for (i = 0; i < 16; i++)
{
PORTD.term_1_wire = 0;
delay_us (1);
PORTD.term_1_wire = 1;
delay_us (1);
}
PORTD.term_1_wire = 0;
DDRD.term_1_wire = 0;
PORTD.term_VDD = 1;
}
{
unsigned char i;
reset_1_wire ();
for (i = 0; i < 8; i++) write_1_wire ();
if ((command & 0xf0) == 0xa0) for (i = 0; i < 8; i++) read_1_wire ();
if ((command & 0xf0) == 0x00)
{
buf_write_1_wire = data;
for (i = 0; i < 8; i++) write_1_wire ();
}
}
{
unsigned char i;
delay_us (1);
DDRD.term_1_wire = 0;
delay_us (8);
i = PIND.term_1_wire;
delay_us (85);
buf_read_1_wire = ((buf_read_1_wire >> 1) & 0x7f) | (i << 7);
}
{
DDRD.term_1_wire = 1;
delay_us (8);
if ((buf_write_1_wire & 0x01) == 0x01)
{
DDRD.term_1_wire = 0;
delay_us (85);
}
else
{
delay_us (85);
DDRD.term_1_wire = 0;
}
buf_write_1_wire = buf_write_1_wire >> 1;
}
Ответы