📄 interface.c
字号:
/** \file
<b>USB receive and transmit</b><br>
Autor: Matthias Wei遝r<br>
Copyright 2005: Matthias Wei遝r<br>
License: QPL (see license.txt)
<hr>
*/
#include "stk500.h"
unsigned char checksum;
//#ifdef CONFIG_INTERFACE_USB
#if 0
//Hardware
#define USB_TXE (PINB&BIT6_POS)
#define USB_RXF (PINC&BIT3_POS)
#define USB_RD_ON PORTC&=BIT1_NEG
#define USB_RD_OFF PORTC|=BIT1_POS
#define USB_WR_ON PORTC|=BIT2_POS
#define USB_WR_OFF PORTC&=BIT2_NEG
/**
Initializes the usb interface
*/
void interface_init(void)
{
PORTC |= BIT1_POS; //USB_RD inactive
DDRC |= BIT1_POS|BIT2_POS; //USB_RD, USB_WR as output
}
/**
Reads a byte from the USB interface
@return received character or -1 if no character has been received
*/
signed int interface_getc(void)
{
unsigned char t;
if(!USB_RXF)
{
USB_RD_ON;
asm("NOP");
t = PIND;
USB_RD_OFF;
return t;
}
else return -1;
}
/**
Writes a byte to the USB
@param t Byte to be written
*/
void interface_putc(unsigned char t)
{
while(USB_TXE);
//PORTD auf Ausgang
DDRD = 0xFF;
//Daten auf den Port
PORTD = t;
USB_WR_ON;
USB_WR_OFF;
//PORTC auf Eingang
DDRD = 0x00;
//Pull-Ups ein
PORTD = 0xFF;
checksum ^= t;
}
#endif
#ifdef CONFIG_INTERFACE_RS232
/**
Initializes the rs232 interface
3.6864MHz
Autor: Lukas Salzburger
*/
void interface_init(void) {
#ifndef __iom88v_h /*meag8*/
UCSRB = (1<<RXEN) | (1<<TXEN);
UBRRL = 1;
UBRRH = 0;
#else /*mega88*/
UCSR0B = (1<<RXEN0) | (1<<TXEN0);
UBRR0L = 1;
UBRR0H = 0;
#endif
}
/**
Reads a byte from the UART interface
Autor: Lukas Salzburger
@return received character or -1 if no character has been received
*/
signed int interface_getc(void) { /*获取PC机发来的一字节信息*/
#ifndef __iom88v_h /*meag8*/
if (UCSRA & (1<<RXC)) {
return UDR;
}
else {
return -1;
}
#else /*mega88*/
if (UCSR0A & (1<<RXC0)) {
return UDR0;
}
else {
return -1;
}
#endif
}
/**
Writes a byte to the UART
Autor: Lukas Salzburger
@param t Byte to be written
*/
void interface_putc(unsigned char t) {
#ifndef __iom88v_h /*meag8*/
while (!(UCSRA & (1<<UDRE)));
UDR = t;
checksum ^= t;
#else /*mega88*/
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = t;
checksum ^= t;
#endif
}
#endif
/**
Writes a string to USB
@param s The string to be send
*/
void interface_print(unsigned char *s)
{
while(*s)
{
interface_putc(*s);
s++;
}
}
/**
Sends a 16 bit value over the USB
MSB first
@param t Value to be send
*/
void interface_put16(unsigned int t)
{
interface_putc((t>>8)&0xFF);
interface_putc((t>>0)&0xFF);
}
/**
Resets the checksum accumulator
*/
void interface_reset_check(void)
{
checksum=0;
}
/**
Sends the accumulated checksum
*/
void interface_send_check(void)
{
interface_putc(checksum);
checksum=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -