Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - forkee

Pages: [1]
1
ตามหัวข้อครับ ขอถามคนที่มีประสบการณ์ครับ ว่าจะขายในช่องทางไหนได้บ้างครับ

2
คือผมเขียนโปรแกรมเพื่อที่จะอ่านและเขียนค่า config ครับ โดยที่เขียนค่า config เป็น structure ไปเก็บที่ eeprom ครับ ตอน compile มันก็ผ่านปกติครับ แต่ตอนรันมันกลับเป็น
ตามรูปที่แนบครับ มันไม่ยอมกลับมาที่โปรแกรมเหมือนเดิมครับ รบกวนผู้รู้ด้วยครับ

ปล.ผมใช้ Attiny2313 ครับ

Code: [Select]
/*
 * Firmware.c
 *
 * Created: 21/2/2556 21:18:31
 *  Author: Tom
 */

#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <compat/deprecated.h>
#include <util/delay.h>
#include <avr/eeprom.h>

//Define CPU clock
#define F_CPU 11059200UL
//Define macro
#define PARITY_NONE 0 //
#define DATA_BIT_8 ((1<<UCSZ1)|(1<<UCSZ0))
#define STOP_BITS_1 0
#define High 2
#define Low 1
#define Off 0
#define True 1
#define False 0
#define EEADDR 0
//Define type
typedef struct
{
//About part
//unsigned char FIRMWARE_VERSION[4]; //Firmware version
//unsigned char AUTHOR[16];//Authority=
//Input assign
unsigned char LOW_PRESSURE;
unsigned char HIGH_PRESSURE;
unsigned char TEMP_HIGH;
//Output assign
unsigned char IGNITOR;
unsigned char MAIN_VALVE;
unsigned char PILOT_VALVE;
unsigned char BLOWER;
//Delay assign
unsigned int BEFORE_PILOT;
unsigned int BRFORE_MAIN_VALVE;
unsigned int BEFORE_BLOWER;
unsigned int BEFORE_COMPLETE;
unsigned int BEFORE_TEMP_MONITOR;
unsigned int AFTER_RESTART;
} Config;
//Global variable
volatile Config EEMEM Test;
volatile Config Tconfig={0,1,2,0,1,2,3,10000,10000,10000,10000,10000,5000};

//Define variable
unsigned char State=0; //Define state variable
#define Idle 0 //Idle state
#define Igniter_On 1 //Start igniter state
#define Pilot_Valve_On 2 //Start pilot valve state
#define Main_Valve_On 3 //Start main valve state
#define Blower_On 4 //Start main blower state
#define Complete 5  //Stop igniter
#define Temp_monitor 6 //Monitor temp

unsigned char I0,I1,I2,I3;
int main(void)
{

Init();
//LoadConfig();
WriteConfig();


    while(1)
    {
        //TODO:: Please write your application code
Run();
    }
}

void Init()
{
Init_input();
Init_output();
USART_Init(71); //Init serial with baud rate 9600 bps
//Set I-bit global interrupt enable
sei();
}
void Init_input()
{
//Init digital input
//PD2,PD3,PD4,PD5
DDRD=(0<<DDD2)|(0<<DDD3)|(0<<DDD4)|(1<<DDD5);
}
void Init_output()
{
//Init digital output
//PB0,PB1,PB2,PB3,PB4,PB5,PB6,PB7
DDRB=(1<<DDB0)|(1<<DDB1)|(1<<DDB2)|(1<<DDB3)|(1<<DDB4)|(1<<DDB5)|(1<<DDB6)|(1<<DDB7);
PORTB=0x00;
}
void delay_ms(unsigned int i)
{
for (;i>0;i--)
{
_delay_ms(1);
}
}
void Put_string(unsigned char *s)
{
while (*s!=0)
{
loop_until_bit_is_set(UCSRA,UDRE);
UDR=*s++;
}

}
void USART_Init(unsigned int baud)
{
//Set baud rate
UBRRH=(unsigned char) (baud>>8);
UBRRL=(unsigned char) (baud);

//Enable receiver and transmitter
UCSRB=(1<<RXEN)|(1<<TXEN);
//Enable interrupt
UCSRB |= (1<<RXCIE)|(1<<TXCIE);

//Set frame format : 8 bit data,None parity,1 stop bit
UCSRC=DATA_BIT_8|PARITY_NONE|STOP_BITS_1;
}
ISR (USART_RX_vect)
{


return;
}
ISR(USART_TX_vect)
{


return;
}
void LoadConfig()
{
eeprom_read_block((void*)&Tconfig,(const void*)&Test,sizeof(Config));
}

void WriteConfig()
{
eeprom_update_block((const void*)&Tconfig,(void*)&Test,sizeof(Config));
}
char CheckPressure()
{
I0=PIND&1<<Tconfig.LOW_PRESSURE; //Assign low pressure scan
I1=PIND&1<<Tconfig.HIGH_PRESSURE; //Assign high pressure scan

if ((I0|I1)==0x0C){
return High;}
if((I0|I1)==0x04){
return Low;}
else{
return Off;}
}

char CheckTemp()
{
I2=PIND&1<<Tconfig.TEMP_HIGH; //Assign temp scan

if (I2==0){
return False;}
else{
return True;}
}
void Run()
{
switch(State)
{
case Idle:
PORTB=0x00; //Clear all output
if (CheckPressure()==High)
State=Igniter_On;
break;

case Igniter_On:
if (CheckPressure()==Off){
State=Idle;
break; }
sbi(PORTB,0); //Start igniter
delay_ms(Tconfig.BEFORE_PILOT); //Worm-up heater before start pilot valve
State=Pilot_Valve_On;
break;

case Pilot_Valve_On:
if (CheckPressure()==Off){
State=Idle;
break; }
sbi(PORTB,1); //Start pilot valve
delay_ms(Tconfig.BRFORE_MAIN_VALVE); //Pilot start before burn
State=Main_Valve_On;
break;

case Main_Valve_On:
if (CheckPressure()==Off){
State=Idle;
break; }
sbi(PORTB,2); //Start main valve
delay_ms(Tconfig.BEFORE_BLOWER);
State=Blower_On;
break;

case Blower_On:
if (CheckPressure()==Off){
State=Idle;
break; }
sbi(PORTB,3); //Start main blower
delay_ms(Tconfig.BEFORE_COMPLETE);
State=Complete;
break;

case Complete:
if (CheckPressure()==Off){
State=Idle;
break; }
cbi(PORTB,0); //Stop igniter
cbi(PORTB,1); //Stop pilot valve
delay_ms(Tconfig.BEFORE_TEMP_MONITOR);
State=Temp_monitor;
break;

case Temp_monitor:
if (CheckPressure()==Off){
State=Idle;
break; }
if (CheckTemp()==False){
sbi(PORTB,0); //Start igniter
delay_ms(Tconfig.BEFORE_PILOT);
sbi(PORTB,1); //Start pilot valve
delay_ms(Tconfig.AFTER_RESTART); //Delay before stop igniter and stop pilot valve
cbi(PORTB,0); //Stop igniter
cbi(PORTB,1); //Stop pilot valve
delay_ms(Tconfig.BEFORE_TEMP_MONITOR); //Delay before check temp
}
break;
}
}

Pages: [1]