Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lab 4 - RS-232 Serial Interface Waveform
- // Troy Dowling, A00817082
- // 2015-10-05
- #include <stdio.h>
- #include <stdbool.h>
- #include <inttypes.h>
- #define BAUD_RATE_HZ 9600
- #define SAMPLE_RATE_HZ 38400
- #define SAMPLES_PER_PULSE (SAMPLE_RATE_HZ / BAUD_RATE_HZ)
- #define MARKL 0x00
- #define MARKH 0x00
- #define SPACEL 0xFF
- #define SPACEH 0x3F
- void tputw(bool input)
- {
- if(input)
- {
- // Mark
- for(int i = SAMPLES_PER_PULSE; i; i--)
- {
- putc(MARKL, stdout);
- putc(MARKH, stdout);
- }
- }
- else
- {
- // Space
- for(int i = SAMPLES_PER_PULSE; i; i--)
- {
- putc(SPACEL, stdout);
- putc(SPACEH, stdout);
- }
- }
- }
- int main(void)
- {
- // This is the string to pipe out over UART
- char str[] = "Troy Dowling A00817082\r\n";
- // For each character in the string
- for(int i = 0; i < sizeof(str)/sizeof(str[0]); i++)
- {
- // Output start bit
- tputw(false);
- // Output each bit in the character
- uint8_t mask = 0x01;
- for(int i = 0; i < 8; i++)
- {
- if(str[i] & mask)
- tputw(true);
- else
- tputw(false);
- mask <<= 1;
- }
- // Output the stop bit
- tputw(true);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement