#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/delay.h>
#include <stdbool.h>
#include "lcdrunn.h"
#define MOSI PB5
#define MISO PB6
#define SCK PB7
#define CS PB4
#define PORT_SPI PORTB
#define CS_HIGH PORTA |= (1 << CS);
#define CS_LOW PORTA &= ~(1 << CS)
#define EEMEM __attribute__((section(".eeprom")))
void InitSpi()
{
DDRB |= (1 << MOSI) | (1 << SCK) | (1 << CS) ;
// Define the following pins as output
//DDRA |= (1 << CS);
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0)|(SPIE);
SPSR |= (1 << SPI2X);
}
//wysyłanie do adc
void SendSpi(uint8_t bajt)
{
SPDR = bajt;
while( !(SPSR & (1 << SPIF)) );
}
//odbiór z adc
uint8_t ReceiveSpi( void )
{
while( !(SPSR & (1 << SPIF)) );
return SPDR;
}
int main(void)
{
lcd_init(); //inicjalizacja wyswietlacza
InitSpi();
uint8_t send[3] = {0x0C, 0x00, 0x00};
CS_HIGH;
while(1)
{
lcd_cls();
uint16_t sum = 978;
uint8_t wyn1 = 12;
uint8_t wyn2 = 21;
CS_LOW;
SendSpi(send[0]);
ReceiveSpi();
SendSpi(send[1]);
wyn1 = ReceiveSpi();
wyn1 = wyn1 & 0b00111111; // albo 0b00011..
SendSpi(send[2]);
wyn2 = ReceiveSpi();
CS_HIGH;
_delay_us(20);
sum = wyn1;
sum = sum << 8;
sum |= wyn2;
lcd_int(sum);
_delay_ms(1000);
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}