I don’t think you need to code even a single line to get it done!
Just enable capping for your ad unit and let AdMob handle the rest for you!