Thomas,
Here is my code.
/*********************************************
This program was produced by the
CodeWizardAVR V1.23.8d Evaluation
Automatic Program Generator
© Copyright 1998-2003 HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro
Project :
Version :
Date : 12.4.2006
Author : Freeware, for non-commercial use only
Company :
Comments:
Chip type : AT90S2313
Clock frequency : 8,000000 MHz
Memory model : Tiny
External SRAM size : 0
Data Stack size : 32
*********************************************/
#include <90s2313.h>
#include <delay.h>
#include <stdlib.h>
#define SCLK PORTD.2
#define DOUT PIND.5
#define NCS PORTD.3
#define NSHDW PORTD.4
// Declare your global variables here
void uart_putc(unsigned char data){
UDR=data;
delay_ms(10);
}
void uart_puts( char *s){
while(*s)
uart_putc(*s++);
}
void uart_puti(const int val){
char buffer[sizeof(int)*8+1];
itoa(val, buffer);
uart_puts(buffer);
}
void init(){
SCLK = 0;
NCS = 0;
}
void doSCLK(void){
SCLK = 1;
delay_us(50);
SCLK = 0;
delay_us(50);
return;
}
int receive(void){
int i,data;
doSCLK();
data=0;
for(;DOUT==0;);
for(i=0;i<12;i++){ doSCLK(); data=(data<<1)|DOUT;}
NCS = 1;
return(data);
}
void main(void)
{
DDRD = 0xdc; // inital output and input pins
UCR=0x18; // initla UART
UBRR=0x33;
while (1)
{
// Place your code here
init();
uart_puti(receive());
UDR = ' ';
}
}