⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb.c

📁 我制作过的usbisp资料, 仅供参考
💻 C
字号:
/**	\file 
	<b>USB receive and transmit</b><br>
	Autor: Matthias Wei遝r<br>
	Copyright 2004: Matthias Wei遝r<br>
	License: QPL (see license.txt)
	<hr>
*/

#include <avr/io.h>
#include "tools.h"
#include "usb.h"

//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

/**
	Reads a byte from the USB interface
	
	@return received character or -1 if no character has been received
*/
signed int usb_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 usb_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;
}

/**
	Writes a string to USB
	
	@param s The string to be send
*/
void usb_print(unsigned char *s)
{
	while(*s)
	{
		usb_putc(*s);
		s++;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -