Page 178 - Programming Microcontrollers in C
P. 178

Microcontroller Memory    163

                   void program(int,int );
                   void erase(int );

                   0101 0101 00FF int EEPROM[0xff] @0x101;


                   void program(int address, int value)
                   0050 0051 {
                   0801 BF 50 STX $50
                   0803 B7 51 STA $51
                   0805 12 07 BSET 1,$07 EEPROM_CTL.E1LAT=1;
                   0807 D7 01 01 STA $0101,X EEPROM[address]=value;
                   080A 10 07 BSET 0,$07 EEPROM_CTL.E1PGM=1;
                   080C 5F CLRX delay(PROG_TIME);
                   080D A6 0A LDA #$0A
                   080F CD 00 00 JSR $****
                   0812 13 07 BCLR 1,$07 EEPROM_CTL.E1LAT=0;


                   0814 81 RTS }

                              void erase(int x)
                   0052 {
                   0815 B7 52 STA $52
                   0817 12 07 BSET 1,$07 EEPROM_CTL.E1LAT=1;
                   0819 14 07 BSET 2,$07 EEPROM_CTL.E1ERA=1;
                   081B 97 TAX EEPROM[x]=0;
                   081C 4F CLRA
                   081D D7 01 01 STA $0101,X
                   0820 10 07 BSET 0,$07 EEPROM_CTL.E1PGM=1;
                   0822 5F CLRX delay(PROG_TIME);
                   0823 A6 0A LDA #$0A
                   0825 CD 00 00 JSR $****
                   0828 13 07 BCLR 1,$07 EEPROM_CTL.E1LAT=0;



                   082A 81 RTS }

                              The function program() requires 20 bytes and the function
                          erase requires 22. This is a good point to explore some of the C
                          programming practices that can lead to poor M68HC05 family com­
   173   174   175   176   177   178   179   180   181   182   183