my code
Code: Select all
#define BAUD_RATE 9600
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include "usbdrv/usbdrv.h"
#include "usbdrv/oddebug.h"
#include "usbdrv/uart.h"
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
static void avr_init(void);
void uart_init(void);
int uart_getch(FILE *stream);
int uart_putch(char ch, FILE *stream);
char * b;
void uart_gets( char* Buffer, uint8_t MaxLen );
uchar usbFunctionSetup(uchar data[8])
{
return USB_NO_MSG;
}
int i;
uchar usbFunctionWrite(uchar *data, uchar len)
{
printf("not work this founction");// not work
scanf("%d",&b);//not work
for (i=0;i<=5;i++)
data[i]=b[i];
return 6;
}
uchar usbFunctionRead(uchar *data, uchar len)
{
scanf("%d",&b);//not work
for (i=0;i<=5;i++)
data[i]=b[i];
return 6;
}
int main(void)
{
avr_init();
for(;;)
{
wdt_reset();
usbPoll();
scanf("%d",&b);//not work
}
return(0);
}
static void avr_init(void)
{
wdt_enable(WDTO_1S);
usbDeviceDisconnect();
int j=0;
uart_init();
FILE uart_str = FDEV_SETUP_STREAM(uart_putch, uart_getch, _FDEV_SETUP_RW);
stdout = stdin = &uart_str;
DDRB|=_BV(0);
printf("hamed");//it is working
_delay_ms(300);
usbDeviceConnect();
usbInit();
odDebugInit();
sei();
return;
}
void uart_init(void)
{
UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8; // set baud rate
UBRRL = (((F_CPU/BAUD_RATE)/16)-1);
UCSRB = (1<<RXEN)|(1<<TXEN);
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
}
int uart_putch(char ch, FILE *stream)
{
if (ch == '\n')
uart_putch('\r', stream);
while (!(UCSRA & (1<<UDRE)));
UDR=ch;
return 0;
}
int uart_getch(FILE *stream)
{
unsigned char ch;
while (!(UCSRA & (1<<RXC)));
ch=UDR;
uart_putch(ch,stream);
return ch;
}
plese help me .......