Вопрос плёвый, для тех кто знает с++ и avr ки.
Я пишу программу которая бы считала булевые функции.
Примерно все выглядит так
http://s15.radikal.ru/i189/1105/de/02df1c273954.jpg
Вот мой сорс
Код: Выделить всё
/*
* Boolean_function.c
*
* Created: 12.05.2011 20:19:52
* Author: Wir_Wolf
*/
#define F_CPU 8000000UL
#include <string.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include "UART_routines.h"
#include "temp.h"
//#define ProgramUP PORTB,0;
//#define ProgramDOWN PORTB,1;
//#define on 1;
//#define off 0;
//#define is_high(x,y) (x & _BV(y)) == _BV(y) //(for input) checks if the input is high (Logic 1)
//#define sbi(x,y) x |= _BV(y) //set bit
//#define cbi(x,y) x &= ~(_BV(y)) //clear bit
#define BUTTON1 PINB.0
#define BUTTON2 PINB.1
#define BUTTON3 PINB.2
void Konjunkcija(void);
int main( void )
{
unsigned char buff[40];
int programma = 0;
int i;
unsigned char temp, pressedButton, myCounter=0;
uart0_init();
_delay_ms(10);
sendStr0("*****Hello*****");
sprintf(buff,"Booleon Function ©Wir_Wolf");
transmitString(buff);
DDRC=0xff;
DDRB = 0000;
/* for(i = 1; i <= 1000; i++) // цикл "для", повторяющийся 10 раз
{
PORTC |= _BV(PC0); // установить "1" (высокий уровень) на выводе PD1,
//зажечь светодиод
_delay_ms(250); // ждем 0.25 сек.
PORTC &= ~_BV(PC0); // установить "0" (низкий уровень) на выводе PD1,
//погасить светодиод
_delay_ms(250); // ждем 0.25 сек.
}*/
while(1)
{
if (PINB.0 == 0)
{ // Кнопка на PC0 - сброс клавиатуры
PORTC |= _BV(PC0);//зажечь светодиод
_delay_ms(250); // ждем 0.25 сек.
PORTC &= ~_BV(PC0);
_delay_ms(250);
}
}
/*while(1)
{
pressedButton = ~PINB;
if (pressedButton) // Check if any button is pressed
{
switch ( pressedButton )
{
case (1<<PB0):
PORTC |= _BV(PC0);//зажечь светодиод
_delay_ms(250); // ждем 0.25 сек.
PORTC &= ~_BV(PC0);
_delay_ms(250);
break;
case (1<<PB1):
break;
case (1<<PB2):
break;
}
}
/* switch(programma){
case 1:Konjunkcija();break;
case 2:Konjunkcija();break;
}
}*/
}
void Konjunkcija(){
uart0_init();
_delay_ms(10);
sendStr0("Function Konjunkcija");
}
тут 70% закоментировано так как я тупо не могу получить значение. Нужно настроить первых 4 прина порта B на вход.
PB0 и PB1 это конкпи переключения между программами. а PB2 и PB3 x и у. Сколько я уже не изголялся над кодом.
В нете нашел пример кода типу
#define BUTTON1 PINB.0
if(BUTTON1==0) то инкрементим щетчик в котором номер программы.
авр студия как всегда отчлечается своим умом и сообразительностью.
Error 4 expected ')' before numeric constant C:\Users\Wir_Wolf\Desktop\bool\Boolean_function\Boolean_function.c 78 18 Boolean_function
http://easyelectronics.ru/avr-uchebnyj- ... atury.html
а тут все хороше компилится
потом нашел некий сорс тоже с обработчиками кнопок
http://forum.cxem.net/index.php?showtop ... t&p=579342
скачал, все зашибись.
код примерно
Код: Выделить всё
while(1)
{
pressedButton = ~PIND;
if (pressedButton) // Check if any button is pressed
{
do{temp = ~PIND;} // Wait until key released
while (temp);
switch ( pressedButton )
{
// Send a Generall Call
case (1<<PD0):
messageBuf[0] = TWI_GEN_CALL; // The first byte must always consit of General Call code or the TWI slave address.
messageBuf[1] = 0xAA; // The command or data to be included in the general call.
TWI_Start_Transceiver_With_Data( messageBuf, 2 );
break;
// Send a Address Call, sending a command and data to the Slave
case (1<<PD1):
messageBuf[0] = (TWI_targetSlaveAddress<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); // The first byte must always consit of General Call code or the TWI slave address.
messageBuf[1] = TWI_CMD_MASTER_WRITE; // The first byte is used for commands.
messageBuf[2] = myCounter; // The second byte is used for the data.
TWI_Start_Transceiver_With_Data( messageBuf, 3 );
break;
// Send a Address Call, sending a request, followed by a resceive
case (1<<PD2):
// Send the request-for-data command to the Slave
messageBuf[0] = (TWI_targetSlaveAddress<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); // The first byte must always consit of General Call code or the TWI slave address.
messageBuf[1] = TWI_CMD_MASTER_READ; // The first byte is used for commands.
TWI_Start_Transceiver_With_Data( messageBuf, 2 );
TWI_operation = REQUEST_DATA; // To release resources to other operations while waiting for the TWI to complete,
// we set a operation mode and continue this command sequence in a "followup"
// section further down in the code.
/*
// Get status from Transceiver and put it on PORTB
case (1<<PD5):
PORTB = TWI_Get_State_Info();
break;
// Increment myCounter and put it on PORTB
case (1<<PD6):
PORTB = ++myCounter;
break;
// Reset myCounter and put it on PORTB
case (1<<PD7):
PORTB = myCounter = 0;
break;*/
}
} взял этот кусок кода влепил в свой, выставил порты, запустил, оно тупо не отрабатывает когда я нажимаю кнопку.
Пробовал подавать вместо логического 0 логическую 1 -- тоже никак.
Поставил деббагер в свичь
Код: Выделить всё
case (1<<PB0):
sendStr0("Button1 == 1");
break;Терминал молчит.
Мне подсказали что нужно каким то образом перестроить порт, чтобы он принимал аналоговый сигнал, а цифровой, но как это сделать не неаю.