First - try removing the battery cables and cleaning the cable ends and battery posts up. Sometimes it is just a dirty corroded connection that is causing the problem. If the battery is old enough to need replacement (3-4 years or older), it would probably be a good investment to just go ahead and replace it.
take it out then replace it
You will have to replace it. It just might not be able to hold the charge. Also, check the charge rate at the battery, with the rev's up around 2,600 you should get around 14 volts.
Put a battery charger on it.
Only if the battery fails the load test.
Go to an authorized Honda dealer.
The battery has a dead cell and needs replacing or something is on pulling power from the battery.
Something is on drawing power from the battery or the battery has a dead cell and needs replacing.
Remove the cables from the battery posts. Remove the battery retaining wedges. This can be accomplished by turning the screws to the left. The battery will come loose. Lift the battery out.
The most common cause for your 1997 Honda Civic lights to dim is a bad alternator. The alternator is not charging the battery. The battery retains a small charge, but not enough charge to run the engine.
Remove the battery from under the driver's seat. Connect it to a small battery charger suitable for motorbikes. Connect the leads to the terminals. Charge until the meter on the charger shows that the battery is fully charged.
If you are 100% sure the battery and alternator are good and the battery is loosing it's charge then something is on pulling power from the battery. Can be any light or any relay on the vehicle.
You wont lose the code by changing the battery. Just open the back and replace the battery . Make sure you use the correct battery and install in properly.