/*
 *
 *  ALL03
 *
 *  26.07.2002
 *
 *  by Fabio Sturman
 *
 *  fabio.sturman@tiscali.it
 *
 *  89c52.h
 *
 *  main module include file
 *
 */

/* Copyright (c) 2002 Fabio Sturman (fabio.sturman@tiscali.it)
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

/*- ATMEL 89C52 Level1--------------------------------------*/

#define NPROG 30
#define NEA   31
#define RDY   14
#define NPSEN 29

#define wr_nprog(x) all03_wr_pin(NPROG,x)
#define pulse_nprog_10ms() pulse_nprog_x(10.0)
#define pulse_nprog_100us() pulse_nprog_x(0.1)
#define pulse_nprog_1ms() pulse_nprog_x(1.0)
#define wr_rst(x) all03_wr_pin(9,x)
#define wr_fpm0(x) all03_wr_pin(27,x)
#define wr_fpm1(x) all03_wr_pin(28,x)
#define wr_fpm2(x) all03_wr_pin(16,x)
#define wr_fpm3(x) all03_wr_pin(17,x)
#define set_clock() all03_select_f_osc(1); all03_set_osc_18_19(1)
#define set_nea_12v() all03_set_vhh_pin(NEA,1)
#define reset_nea_12v() all03_set_vhh_pin(NEA,0)
#define wr_nea(x) all03_wr_pin(NEA,x)
#define rd_rdy() all03_rd_pin(RDY)
#define wr_npsen(x) all03_wr_pin(NPSEN,x)
#define short_delay() all03_rd_pin(RDY)


/*- ATMEL 98C52 Level2--------------------------------------*/

#define COMMAND_WRITE_CODE_DATA       0x0e
#define COMMAND_READ_CODE_DATA        0x0c
#define COMMAND_CHIP_ERASE            0x01
#define COMMAND_READ_SIGNATURE_BYTE   0x00
#define COMMAND_WRITE_LOCK_BIT_1      0x0f
#define COMMAND_WRITE_LOCK_BIT_2      0x03
#define COMMAND_WRITE_LOCK_BIT_3      0x05

#define PROC_STRING "Insert AT89C5x and press <ENTER>\n"

#define print_model_and_voltage() printf("Model: 89C5%d  Programming voltage (Vpp): %dV  Programming pulse (Tp): %s\n", \
    micro_controller_model, programming_voltage, (long_delay?"10ms":"100us"));


/*- ATMEL 89C52 Level1--------------------------------------*/

void wr_chip_data(unsigned char ub); 
unsigned char rd_chip_data(void);
void pulse_nprog(void);
void pulse_nprog_x(float x);
void wr_fpm(unsigned char fpm);
void wr_chip_address(unsigned short address);
int wait_rdy(void);
void chip_init(void);

/*- ATMEL 89C52 Level2--------------------------------------*/

void edit_model_and_voltage(void);
void print_lock_bits(void);
void edit_lock_bits(void);
void write_lock_bits(void);
void erase(void);
void read_signature(void);
void write(void);
void read(void);
void blank_check(void);
void verify(void);
void display_help(void);
void read_flash_buf_from_file(void);
void write_flash_buf_to_file(void);
void display_help(void);
int main(int argc, char *argv[]);


