Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 1000000UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- int delayTime;
- int cur;
- int dest;
- ISR(TIMER1_OVF_vect) {
- cur++;
- if(cur < dest) {
- TCNT1 = delayTime;
- }
- }
- void startTimer(int destValue, int delay) {
- cur = 0;
- dest = destValue;
- delayTime = 256 - delay;
- TCNT1 = delayTime;
- }
- void sendBit(int bitValue) {
- if(bitValue == 1) {
- //560 high, 1680 low
- PORTB |= (1 << 4);
- startTimer(1, 140);
- PORTB &= ~(1 << 4);
- startTimer(2, 210);
- } else {
- //560 high, 560 low
- PORTB |= (1 << 4);
- startTimer(1, 140);
- PORTB &= ~(1 << 4);
- startTimer(1, 140);
- }
- }
- void sendCommand(char state) {
- PORTB |= (1 << 4);
- startTimer(50, 45);
- PORTB &= ~(1 << 4);
- startTimer(5, 225);
- int pos = 0;
- while(pos < 8) {
- sendBit((state >> pos) & 1);
- pos++;
- }
- PORTB |= (1 << 4);
- startTimer(1, 140);
- PORTB &= ~(1 << 4);
- }
- int main(void)
- {
- DDRB = 0;
- PORTB = 0;
- DDRB |= (1 << 4);
- //PORTB |= (1 << 4);
- TCCR1 |= (1 << CS11) | (1 << CS10);
- TIMSK = 0b00000010;
- sendBit(0);
- /*
- char enable = 0xFA;
- char white = 0x2F;
- sendCommand(enable);
- sendCommand(white);
- */
- while (1)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement